#include <cstdio> using namespace std; long long min(long long a, long long b) { return a < b ? a : b; } int main() { long long int n,m,a,b,d,prev; scanf("%lld%lld", &n, &m); long long int *A = new long long int[n + 1]; long long int *C = new long long int[n + 1]; for (int i = 0; i < n; i++) { scanf("%lld", &a); A[i] = a; C[i] = 0; } prev = 0; while (m--) { long long sum = 0; scanf("%lld%lld", &d, &b); for (int i = 0; i < n; i++) { C[i] += A[i] * (d - prev); if (C[i] > b) sum += C[i] - b; C[i] = min(C[i], b); } prev = d; printf("%lld\n", sum); } delete [] A; delete [] C; 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 | #include <cstdio> using namespace std; long long min(long long a, long long b) { return a < b ? a : b; } int main() { long long int n,m,a,b,d,prev; scanf("%lld%lld", &n, &m); long long int *A = new long long int[n + 1]; long long int *C = new long long int[n + 1]; for (int i = 0; i < n; i++) { scanf("%lld", &a); A[i] = a; C[i] = 0; } prev = 0; while (m--) { long long sum = 0; scanf("%lld%lld", &d, &b); for (int i = 0; i < n; i++) { C[i] += A[i] * (d - prev); if (C[i] > b) sum += C[i] - b; C[i] = min(C[i], b); } prev = d; printf("%lld\n", sum); } delete [] A; delete [] C; return 0; } |