#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5 + 9; int speed[MAX_N]; long long grass[MAX_N]; int n, m; int main() { scanf("%d%d", &n, &m); for(int i = 0; i < n; ++i) { scanf("%d", &speed[i]); } long long day = 0; long long d, b; for(int i = 0; i < m; ++i) { long long sol = 0; scanf("%lld%lld", &d, &b); for(int j = 0; j < n; ++j) { grass[j] += speed[j] * (d - day); sol += max(0ll, grass[j] - (long long)b); grass[j] = min(grass[j], (long long)b); } day = d; printf("%lld\n", sol); } 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 | #include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5 + 9; int speed[MAX_N]; long long grass[MAX_N]; int n, m; int main() { scanf("%d%d", &n, &m); for(int i = 0; i < n; ++i) { scanf("%d", &speed[i]); } long long day = 0; long long d, b; for(int i = 0; i < m; ++i) { long long sol = 0; scanf("%lld%lld", &d, &b); for(int j = 0; j < n; ++j) { grass[j] += speed[j] * (d - day); sol += max(0ll, grass[j] - (long long)b); grass[j] = min(grass[j], (long long)b); } day = d; printf("%lld\n", sol); } return 0; } |