//SIA #include <cstdio> int main() { int numFields,numCuts; int grass[500000]; long long int height[500000]={0}; long long int cuts[500000][2]; scanf("%d %d",&numFields,&numCuts); for(int i=0;i<numFields;i++) { scanf("%d",&grass[i]); } for(int i=0;i<numCuts;i++) { scanf("%lld %lld",&cuts[i][0],&cuts[i][1]); } int prevday=0; for(int j=0;j<numCuts; j++) { long long int daynum=cuts[j][0]-prevday; prevday=cuts[j][0]; long long int sum=0; for(int i=0;i<numFields; i++) { height[i]+=daynum*grass[i]; if( height[i] > cuts[j][1] ) { sum+=(height[i] - cuts[j][1]); height[i] = cuts[j][1]; } } printf("%lld\n",sum); } 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 | //SIA #include <cstdio> int main() { int numFields,numCuts; int grass[500000]; long long int height[500000]={0}; long long int cuts[500000][2]; scanf("%d %d",&numFields,&numCuts); for(int i=0;i<numFields;i++) { scanf("%d",&grass[i]); } for(int i=0;i<numCuts;i++) { scanf("%lld %lld",&cuts[i][0],&cuts[i][1]); } int prevday=0; for(int j=0;j<numCuts; j++) { long long int daynum=cuts[j][0]-prevday; prevday=cuts[j][0]; long long int sum=0; for(int i=0;i<numFields; i++) { height[i]+=daynum*grass[i]; if( height[i] > cuts[j][1] ) { sum+=(height[i] - cuts[j][1]); height[i] = cuts[j][1]; } } printf("%lld\n",sum); } return 0; } |