#include <cstdio> #include <cstdint> #include <climits> const static uint32_t MAX_N = 500000; uint32_t a[MAX_N]; uint64_t w[MAX_N]; using namespace std; int main() { uint32_t n, m, t; uint64_t d, b, last, sum; scanf("%lu %lu", &n, &m); for (uint32_t i = 0; i < n; ++i) { scanf("%lu", &t); a[i] = t; w[i] = 0; } last = 0; for (uint32_t j = 0; j < m; ++j) { scanf("%lu %lu", &d, &b); sum = 0; for (uint32_t i = 0; i < n; ++i) { w[i] += (uint64_t) a[i] * (d - last); if (w[i] > b) { sum += w[i] - b; w[i] = b; } } last = d; printf("%lu\n", sum); } 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 | #include <cstdio> #include <cstdint> #include <climits> const static uint32_t MAX_N = 500000; uint32_t a[MAX_N]; uint64_t w[MAX_N]; using namespace std; int main() { uint32_t n, m, t; uint64_t d, b, last, sum; scanf("%lu %lu", &n, &m); for (uint32_t i = 0; i < n; ++i) { scanf("%lu", &t); a[i] = t; w[i] = 0; } last = 0; for (uint32_t j = 0; j < m; ++j) { scanf("%lu %lu", &d, &b); sum = 0; for (uint32_t i = 0; i < n; ++i) { w[i] += (uint64_t) a[i] * (d - last); if (w[i] > b) { sum += w[i] - b; w[i] = b; } } last = d; printf("%lu\n", sum); } return 0; } |