Submission #758793

#TimeUsernameProblemLanguageResultExecution timeMemory
758793nihonSnowball (JOI21_ho_t2)C++14
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define N 200005 using namespace std; int n,q,x,i,st,dr,mid,sol,l; int v[N],s[N],mn[N],mx[N],k[N],g[N]; int main() { cin>>n>>q; for(i=1;i<=n;++i) { cin>>v[i]; } for(i=1;i<=q;++i) { cin>>x; s[i]=s[i-1]+x; mn[i]=min(mn[i-1],s[i]); mx[i]=max(mx[i-1],s[i]); k[i]=abs(mn[i])+mx[i]; } for(i=1;i<n;++i) { st=1; dr=q; sol=q; l=v[i+1]-v[i]; while(st<=dr) { mid=(st+dr)>>1; if(l>k[mid]) st=mid+1; else {sol=mid; dr=mid-1;} } if(k[sol]<l) { g[i]+=mx[sol]; g[i+1]+=abs(mn[sol]); } else { g[i]+=mx[sol-1]; g[i+1]+=abs(mn[sol-1]); if(mx[sol]>mx[sol-1]) { g[i]+=l-k[sol-1]; } else { g[i+1]+=l-k[sol-1]; } } } g[1]+=abs(mn[q]); g[n]+=mx[q]; for(i=1;i<=n;++i) { cout<<g[i]<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...