#include <cstdio> int main() { int n, m; scanf("%d %d", &n, &m); long long int* t = new long long int[n]; int* d = new int[m]; for (int i = 0; i < n; ++i) { scanf("%lld", &t[i]); } for (int i = 0; i < m; ++i) { scanf("%d", &d[i]); } for (int i = 0; i < m; ++i) { long long int sum = 0; long long int currentTime = 0; for (int j = 0; j < n; ++j) { currentTime += d[i]; if (currentTime > t[j]) { int x = currentTime - t[j]; sum += x; } else { currentTime = t[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 35 36 37 38 39 40 41 42 43 44 | #include <cstdio> int main() { int n, m; scanf("%d %d", &n, &m); long long int* t = new long long int[n]; int* d = new int[m]; for (int i = 0; i < n; ++i) { scanf("%lld", &t[i]); } for (int i = 0; i < m; ++i) { scanf("%d", &d[i]); } for (int i = 0; i < m; ++i) { long long int sum = 0; long long int currentTime = 0; for (int j = 0; j < n; ++j) { currentTime += d[i]; if (currentTime > t[j]) { int x = currentTime - t[j]; sum += x; } else { currentTime = t[j]; } } printf("%lld\n", sum); } return 0; } |