import java.util.Scanner;
public class sia {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int[] a = new int[n];
int[] h = new int[n];
for (int i=0; i<n; i++) {
a[i] = sc.nextInt();
}
int last_d = 0;
for (int i=0; i<m; i++) {
int d = sc.nextInt();
int b = sc.nextInt();
int sum = 0;
System.err.print("day " + d + ", b="+b+" : ");
for(int j=0; j<n; j++) {
h[j] += (a[j] * (d - last_d));
System.err.print(h[j]);
if (h[j] > b) {
sum += h[j] - b;
h[j] = b;
System.err.print("("+h[j]+")");
}
System.err.print(", ");
}
last_d = d;
System.err.println();
System.out.println(sum);
}
}
}
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 | import java.util.Scanner; public class sia { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[] a = new int[n]; int[] h = new int[n]; for (int i=0; i<n; i++) { a[i] = sc.nextInt(); } int last_d = 0; for (int i=0; i<m; i++) { int d = sc.nextInt(); int b = sc.nextInt(); int sum = 0; System.err.print("day " + d + ", b="+b+" : "); for(int j=0; j<n; j++) { h[j] += (a[j] * (d - last_d)); System.err.print(h[j]); if (h[j] > b) { sum += h[j] - b; h[j] = b; System.err.print("("+h[j]+")"); } System.err.print(", "); } last_d = d; System.err.println(); System.out.println(sum); } } } |
English