This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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>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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |