#include <cstdio> int main() { long long n, m, d, b, oldD, sum, mnoznik; d = 0; oldD = 0; scanf("%lld", &n); scanf("%lld", &m); long long *A = new long long[n]; long long *SUM = new long long[n]; for(long long i = 0; i < n; i++) { scanf("%lld", A + i); SUM[i] = 0; } while(m--) { sum = 0; oldD = d; scanf("%lld", &d); scanf("%lld", &b); mnoznik = d - oldD; for(int i = 0; i < n; i++) { SUM[i] += mnoznik * A[i]; if(SUM[i] > b) { sum += SUM[i] - b; SUM[i] = b; } } printf("%lld\n", sum); } }
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 | #include <cstdio> int main() { long long n, m, d, b, oldD, sum, mnoznik; d = 0; oldD = 0; scanf("%lld", &n); scanf("%lld", &m); long long *A = new long long[n]; long long *SUM = new long long[n]; for(long long i = 0; i < n; i++) { scanf("%lld", A + i); SUM[i] = 0; } while(m--) { sum = 0; oldD = d; scanf("%lld", &d); scanf("%lld", &b); mnoznik = d - oldD; for(int i = 0; i < n; i++) { SUM[i] += mnoznik * A[i]; if(SUM[i] > b) { sum += SUM[i] - b; SUM[i] = b; } } printf("%lld\n", sum); } } |