#include <cstdio> using namespace std; int main() { // n i m (1 <= n, m <= 500 000), long n,m; scanf("%ld %ld",&n, &m); // a1, a2, . . . , an (1 <= ai <= 10^6) long long *agrowth = new long long[n*2]; for(long in=0;in<2*n;) { long growth = 0; scanf("%ld", &growth); agrowth[in++] = growth; agrowth[in++] = 0; } //di i bi (1 <= di <= 10^12, 0 <= bi <= 10^12) long long int di, bi; long long int day =0; for(long im=0; im<m; im++) { long long int cutinaday = 0; //scanf("%I64d %I64d",&di, &bi); scanf("%lld %lld",&di, &bi); long long int daydiff = di - day; for(long in=0;in<n*2;) { long long delta = daydiff * agrowth[in++]; long long cut = delta + agrowth[in] - bi; if(cut>0LL) { agrowth[in] = bi; cutinaday += cut; } else{ agrowth[in] += delta; } in++; } day = di; printf("%lld\n", cutinaday); //printf("%I64d\n", cutinaday); } 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 43 44 45 46 47 48 49 50 | #include <cstdio> using namespace std; int main() { // n i m (1 <= n, m <= 500 000), long n,m; scanf("%ld %ld",&n, &m); // a1, a2, . . . , an (1 <= ai <= 10^6) long long *agrowth = new long long[n*2]; for(long in=0;in<2*n;) { long growth = 0; scanf("%ld", &growth); agrowth[in++] = growth; agrowth[in++] = 0; } //di i bi (1 <= di <= 10^12, 0 <= bi <= 10^12) long long int di, bi; long long int day =0; for(long im=0; im<m; im++) { long long int cutinaday = 0; //scanf("%I64d %I64d",&di, &bi); scanf("%lld %lld",&di, &bi); long long int daydiff = di - day; for(long in=0;in<n*2;) { long long delta = daydiff * agrowth[in++]; long long cut = delta + agrowth[in] - bi; if(cut>0LL) { agrowth[in] = bi; cutinaday += cut; } else{ agrowth[in] += delta; } in++; } day = di; printf("%lld\n", cutinaday); //printf("%I64d\n", cutinaday); } return 0; } |