#include <bits/stdc++.h> using namespace std; long long n, m, x, answer, last; long long tab[200006]; void fin(long long &liczba) { bool minus = 0; char c = 0; liczba = 0; while (c<33)c = getchar_unlocked(); do { if (c == '-')minus = 1; else liczba = (liczba << 1) + (liczba << 3) + c - '0'; c = getchar_unlocked(); } while (c>33); if (minus == 1)liczba = -liczba; } int main() { ios_base::sync_with_stdio(0); fin(n); fin(m); for (int i = 1;i <= n;i++) fin(tab[i]); for (int z = 1;z <= m;z++) { fin(x); for (int i = 1;i <= n;i++) { last += x; if (tab[i] < last) answer += last - tab[i]; else last = tab[i]; } cout << answer << endl; answer = 0; last = 0; } //system("pause"); 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 45 46 47 48 49 | #include <bits/stdc++.h> using namespace std; long long n, m, x, answer, last; long long tab[200006]; void fin(long long &liczba) { bool minus = 0; char c = 0; liczba = 0; while (c<33)c = getchar_unlocked(); do { if (c == '-')minus = 1; else liczba = (liczba << 1) + (liczba << 3) + c - '0'; c = getchar_unlocked(); } while (c>33); if (minus == 1)liczba = -liczba; } int main() { ios_base::sync_with_stdio(0); fin(n); fin(m); for (int i = 1;i <= n;i++) fin(tab[i]); for (int z = 1;z <= m;z++) { fin(x); for (int i = 1;i <= n;i++) { last += x; if (tab[i] < last) answer += last - tab[i]; else last = tab[i]; } cout << answer << endl; answer = 0; last = 0; } //system("pause"); return 0; } |