#include <bits/stdc++.h> using namespace std; const int maxn = 1000111; int n, m; long long t[maxn], d; int main () { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &t[i]); for (int i = 1; i <= m; i++) { scanf("%lld", &d); long long res = 0, akt = 0; for (int j = 1; j <= n; j++) { if (d <= t[j] - akt) { akt = t[j]; } else { akt = d + akt; res += akt - t[j]; } } printf("%lld\n", res); } 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 | #include <bits/stdc++.h> using namespace std; const int maxn = 1000111; int n, m; long long t[maxn], d; int main () { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &t[i]); for (int i = 1; i <= m; i++) { scanf("%lld", &d); long long res = 0, akt = 0; for (int j = 1; j <= n; j++) { if (d <= t[j] - akt) { akt = t[j]; } else { akt = d + akt; res += akt - t[j]; } } printf("%lld\n", res); } return 0; } |