import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; public class sia { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader bi = new BufferedReader(new InputStreamReader(System.in)); String line; line = bi.readLine(); long pow = Long.parseLong(line.split(" ")[0]); long sko = Long.parseLong(line.split(" ")[1]); line = bi.readLine(); long wzr[] = Arrays.stream(line.split(" ")).mapToLong(Long::parseLong).toArray(); long[] cur = new long[(int) pow]; long dzi = 0; long ldzi = 0; long ilo = 0; long sum = 0; long count = 0; OutputStream out = new BufferedOutputStream ( System.out ); while(count<sko) { line = bi.readLine(); dzi = Long.parseLong(line.split(" ")[0]); ilo = Long.parseLong(line.split(" ")[1]); sum = 0; for(int i=0; i<wzr.length;i++) { cur[i] += wzr[i]*(dzi-ldzi); if(cur[i]>ilo) { sum+=cur[i]-ilo; cur[i] = ilo; } } out.write((sum + "\n").getBytes()); ldzi = dzi; count++; } out.flush(); out.close(); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; public class sia { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader bi = new BufferedReader(new InputStreamReader(System.in)); String line; line = bi.readLine(); long pow = Long.parseLong(line.split(" ")[0]); long sko = Long.parseLong(line.split(" ")[1]); line = bi.readLine(); long wzr[] = Arrays.stream(line.split(" ")).mapToLong(Long::parseLong).toArray(); long[] cur = new long[(int) pow]; long dzi = 0; long ldzi = 0; long ilo = 0; long sum = 0; long count = 0; OutputStream out = new BufferedOutputStream ( System.out ); while(count<sko) { line = bi.readLine(); dzi = Long.parseLong(line.split(" ")[0]); ilo = Long.parseLong(line.split(" ")[1]); sum = 0; for(int i=0; i<wzr.length;i++) { cur[i] += wzr[i]*(dzi-ldzi); if(cur[i]>ilo) { sum+=cur[i]-ilo; cur[i] = ilo; } } out.write((sum + "\n").getBytes()); ldzi = dzi; count++; } out.flush(); out.close(); } } |