#include <cstdio> #define LL unsigned long long int main() { int n, m, i, j; LL rozn; scanf("%d %d", &n, &m); LL *a = new LL[n]; LL *d = new LL[m]; LL *b = new LL[m]; LL *w = new LL[m]; LL *k = new LL[n]; for(i=0; i<n; i++) { scanf("%llu", &a[i]); k[i] = 0; } for(i=0; i<m; i++) { scanf("%llu %llu", &d[i], &b[i]); w[i] = 0; } for(i=0; i<m; i++) { for(j=0; j<n; j++) { if (i==0) k[j] += a[j]*d[i]; else k[j] += a[j]*(d[i]-d[i-1]); if (k[j] > b[i]) { rozn = k[j] - b[i]; w[i] += rozn; k[j] -= rozn; } } } for (i=0; i<m; i++) printf("%llu\n", w[i]); }
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 | #include <cstdio> #define LL unsigned long long int main() { int n, m, i, j; LL rozn; scanf("%d %d", &n, &m); LL *a = new LL[n]; LL *d = new LL[m]; LL *b = new LL[m]; LL *w = new LL[m]; LL *k = new LL[n]; for(i=0; i<n; i++) { scanf("%llu", &a[i]); k[i] = 0; } for(i=0; i<m; i++) { scanf("%llu %llu", &d[i], &b[i]); w[i] = 0; } for(i=0; i<m; i++) { for(j=0; j<n; j++) { if (i==0) k[j] += a[j]*d[i]; else k[j] += a[j]*(d[i]-d[i-1]); if (k[j] > b[i]) { rozn = k[j] - b[i]; w[i] += rozn; k[j] -= rozn; } } } for (i=0; i<m; i++) printf("%llu\n", w[i]); } |