#include<cstdio>
#define LL long long
const int ZAK=500002;
int n,m,d,b,ak;
LL int w;
int g[ZAK],t[ZAK];
int main(){
scanf("%d%d", &n, &m);
for(int i=0;i<n;i++){
scanf("%d", &g[i]);
}
for(int i=0;i<m;i++){
w=0;
scanf("%d%d", &d, &b);
for(int j=0;j<n;j++){
t[j]+=g[j]*(d-ak);
if(t[j]>b){w+=t[j]-b; t[j]=b;}
}
ak=d;
printf("%lld\n", w);
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<cstdio> #define LL long long const int ZAK=500002; int n,m,d,b,ak; LL int w; int g[ZAK],t[ZAK]; int main(){ scanf("%d%d", &n, &m); for(int i=0;i<n;i++){ scanf("%d", &g[i]); } for(int i=0;i<m;i++){ w=0; scanf("%d%d", &d, &b); for(int j=0;j<n;j++){ t[j]+=g[j]*(d-ak); if(t[j]>b){w+=t[j]-b; t[j]=b;} } ak=d; printf("%lld\n", w); } } |
English