#include <stdio.h> #include <string.h> int main() { int n = 0; int m = 0; int * grass = new int[n]; int * a = new int[n]; int lastTime = 0; scanf("%d", &n); scanf("%d", &m); int nn = n; int mm = m; for (int i=0;i<nn;i++) { int aa; scanf("%d", &aa); a[i] = aa; grass[i] == aa; } int ii = 0; for (int i=0; ii<mm; ii++) { int time; int b; scanf("%d", &time); scanf("%d", &b); for (int j=0;j<nn;j++) { grass[j]+= a[j]*(time-lastTime); } int cut = 0; for (int j=0;j<nn;j++) { if (grass[j] > b) { cut += (grass[j] - b); grass[j]=b; } } printf("%d\n" , cut); lastTime = time; } delete[] grass; delete[] a; }
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 50 51 52 53 54 55 56 | #include <stdio.h> #include <string.h> int main() { int n = 0; int m = 0; int * grass = new int[n]; int * a = new int[n]; int lastTime = 0; scanf("%d", &n); scanf("%d", &m); int nn = n; int mm = m; for (int i=0;i<nn;i++) { int aa; scanf("%d", &aa); a[i] = aa; grass[i] == aa; } int ii = 0; for (int i=0; ii<mm; ii++) { int time; int b; scanf("%d", &time); scanf("%d", &b); for (int j=0;j<nn;j++) { grass[j]+= a[j]*(time-lastTime); } int cut = 0; for (int j=0;j<nn;j++) { if (grass[j] > b) { cut += (grass[j] - b); grass[j]=b; } } printf("%d\n" , cut); lastTime = time; } delete[] grass; delete[] a; } |