#include <bits/stdc++.h> using namespace std; #define endl '\n' int a, b, c, tab[1000001], roz[1000001], d, w; int main () { ios_base::sync_with_stdio(0); cin >> a >> b; for (int i = 0; i < a; i++) { cin >> tab[i]; if (i > 0) roz[i-1] = tab[i] - tab[i-1]; } for (int i = 0; i < b; i++) { cin >> c; for (int j = 0; j < a; j++) { if (d+c <= tab[j]) { d = tab[j]; } else { w += d+c-tab[j]; d = d + c; } } cout << w << endl; w = 0; d = 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 | #include <bits/stdc++.h> using namespace std; #define endl '\n' int a, b, c, tab[1000001], roz[1000001], d, w; int main () { ios_base::sync_with_stdio(0); cin >> a >> b; for (int i = 0; i < a; i++) { cin >> tab[i]; if (i > 0) roz[i-1] = tab[i] - tab[i-1]; } for (int i = 0; i < b; i++) { cin >> c; for (int j = 0; j < a; j++) { if (d+c <= tab[j]) { d = tab[j]; } else { w += d+c-tab[j]; d = d + c; } } cout << w << endl; w = 0; d = 0; } } |