#include <stdio.h> #define MAXT 201000 #define MAXD 201000 long long t[MAXT]; int d[MAXD]; int main() { int m, n; int i, j, k; long long sum; long long last; scanf("%d%d", &n, &m); for (i=0;i<n;i++) scanf("%lld", &t[i]); for (i=0;i<m;i++) scanf("%d", &d[i]); for (j=0;j<m;j++) { sum = 0; last = 0; for (i=0;i<n;i++) { if (last+d[j]<=t[i]) { last = t[i]; } else { sum += (last+d[j]-t[i]); last += d[j]; } } printf("%lld\n", sum); } return 0; }
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 | #include <stdio.h> #define MAXT 201000 #define MAXD 201000 long long t[MAXT]; int d[MAXD]; int main() { int m, n; int i, j, k; long long sum; long long last; scanf("%d%d", &n, &m); for (i=0;i<n;i++) scanf("%lld", &t[i]); for (i=0;i<m;i++) scanf("%d", &d[i]); for (j=0;j<m;j++) { sum = 0; last = 0; for (i=0;i<n;i++) { if (last+d[j]<=t[i]) { last = t[i]; } else { sum += (last+d[j]-t[i]); last += d[j]; } } printf("%lld\n", sum); } return 0; } |