Submission #677773

#TimeUsernameProblemLanguageResultExecution timeMemory
677773rittin1Snowball (JOI21_ho_t2)C++17
0 / 100
2 ms468 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,q; cin >> n >> q; int pos[n+1]; for(int i=1;i<=n;i++){ cin >> pos[i]; } int w[q+2]; w[q+1]=0; w[0]=0; int x; int a[q+2]; a[q+1]=(long long)1e18; //a[0]=0; int mx[q+1]; int mn[q+1]; mn[0]=0; mx[0]=0; for(int i=1;i<=q;i++){ cin >> x; w[i]=w[i-1]+x; mn[i]=min(mn[i-1],w[i]); mx[i]=max(mx[i-1],w[i]); a[i]=mx[i]-mn[i]; } int ans[n+1]; for(int i=1;i<=n;i++){ ans[i]=0; } ans[1]+=(-mn[q]); for(int i=1;i<n;i++){ int diff=pos[i+1]-pos[i]; int ind=lower_bound(a,a+q+2,diff)-a; //cout << ind << '\n'; if(ind!=0){ if(ind>q){ ans[i]+=(mx[q]); ans[i+1]+=(-mn[q]); } else{ ind--; ans[i]+=(mx[ind]); ans[i+1]+=(-mn[ind]); if(w[ind+1]<w[ind]){ ans[i+1]+=pos[i+1]-pos[i]-a[ind]; } else{ ans[i]+=pos[i+1]-pos[i]-a[ind]; } } } } ans[n]+=mx[q]; for(int i=1;i<=n;i++){ cout << ans[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...