#include<cstdio> #define LLI long long int LLI tab[500010], N, M, wyn=0, a[500010], b[500010], pom[500010]; int main(){ scanf("%lld%lld", &N, &M); for(int i=0; i<N; i++) scanf("%lld", &tab[i]); for(int i=1; i<=M; i++){ scanf("%lld%lld", &a[i], &b[i]); for(int j=0; j<N; j++){ pom[j]+=tab[j]*(a[i]-a[i-1]); if(pom[j]>b[i]){ wyn+=pom[j]-b[i]; pom[j]=b[i]; } } printf("%lld\n", wyn); wyn=0; } getchar(); getchar(); 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 | #include<cstdio> #define LLI long long int LLI tab[500010], N, M, wyn=0, a[500010], b[500010], pom[500010]; int main(){ scanf("%lld%lld", &N, &M); for(int i=0; i<N; i++) scanf("%lld", &tab[i]); for(int i=1; i<=M; i++){ scanf("%lld%lld", &a[i], &b[i]); for(int j=0; j<N; j++){ pom[j]+=tab[j]*(a[i]-a[i-1]); if(pom[j]>b[i]){ wyn+=pom[j]-b[i]; pom[j]=b[i]; } } printf("%lld\n", wyn); wyn=0; } getchar(); getchar(); return 0; } |