#include <bits/stdc++.h> using namespace std; #define prev gjsdklgjdslkg typedef long long LL; const int MX = 1e6 + 5; int n, m; LL t[MX], a[MX], prev; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++ i) scanf("%lld", &a[i]); while (m--) { LL d, b; scanf("%lld%lld", &d, &b); for (int i = 1; i <= n; ++ i) t[i] += (d - prev) * a[i]; prev = d; LL res = 0; for (int i = 1; i <= n; ++ i) if (t[i] >= b) { res += t[i] - b; t[i] = b; } 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 30 31 32 33 34 35 36 37 38 | #include <bits/stdc++.h> using namespace std; #define prev gjsdklgjdslkg typedef long long LL; const int MX = 1e6 + 5; int n, m; LL t[MX], a[MX], prev; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++ i) scanf("%lld", &a[i]); while (m--) { LL d, b; scanf("%lld%lld", &d, &b); for (int i = 1; i <= n; ++ i) t[i] += (d - prev) * a[i]; prev = d; LL res = 0; for (int i = 1; i <= n; ++ i) if (t[i] >= b) { res += t[i] - b; t[i] = b; } printf("%lld\n", res); } return 0; } |