#include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int MAXN = 500009; int A[MAXN]; LL B[MAXN]; int main(int argc, char* argv[]) { int n, m; LL d, b, dprev = 0; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &A[i]); while (m--) { scanf("%lld%lld", &d, &b); LL t = d - dprev; LL res = 0; for (int i = 0; i < n; i++) { B[i] += t * A[i]; res += max(0LL, B[i] - b); B[i] = min(B[i], b); } dprev = d; 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 | #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int MAXN = 500009; int A[MAXN]; LL B[MAXN]; int main(int argc, char* argv[]) { int n, m; LL d, b, dprev = 0; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &A[i]); while (m--) { scanf("%lld%lld", &d, &b); LL t = d - dprev; LL res = 0; for (int i = 0; i < n; i++) { B[i] += t * A[i]; res += max(0LL, B[i] - b); B[i] = min(B[i], b); } dprev = d; printf("%lld\n", res); } return 0; } |