#include <cstdio> #include <cstdlib> #include <algorithm> using namespace std; const int N_MAX = 500000; typedef long long int int_t; int_t A[N_MAX]; int_t trawa[N_MAX]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%lld", &A[i]); trawa[i] = 0; } int d_pop = 0; for (int k = 0; k < m; ++k) { int_t d, b; scanf("%lld %lld", &d, &b); int_t result = 0; for (int i = 0; i < n ; ++i) { int_t nowa_trawa = (d - d_pop) * A[i] + trawa[i]; int_t diff = max(nowa_trawa - b, (int_t) 0); result += diff; trawa[i] = nowa_trawa - diff; } d_pop = d; printf("%lld\n", result); } 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 | #include <cstdio> #include <cstdlib> #include <algorithm> using namespace std; const int N_MAX = 500000; typedef long long int int_t; int_t A[N_MAX]; int_t trawa[N_MAX]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%lld", &A[i]); trawa[i] = 0; } int d_pop = 0; for (int k = 0; k < m; ++k) { int_t d, b; scanf("%lld %lld", &d, &b); int_t result = 0; for (int i = 0; i < n ; ++i) { int_t nowa_trawa = (d - d_pop) * A[i] + trawa[i]; int_t diff = max(nowa_trawa - b, (int_t) 0); result += diff; trawa[i] = nowa_trawa - diff; } d_pop = d; printf("%lld\n", result); } return 0; } |