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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
vector <int> a(n+2),re(n+1);
for(int i=1;i<=n;i++)cin>>a[i];
a[n+1]=1e18;a[0]=-1e18;
re[0]=-1e18;
vector <int> x(q+1),mn(q+1),mx(q+1);
for(int i=1;i<=q;i++){
cin>>x[i];
x[i]+=x[i-1];
mn[i]=min(mn[i-1],x[i]);
mx[i]=max(mx[i-1],x[i]);
}
for(int i=1;i<=n;i++){
int l=a[i],r=min(a[i+1],a[i]+mx[q]);
int ans=0;
while(l<=r){
int md=(l+r)/2;
auto pos=lower_bound(all(mx),md-a[i])-mx.begin();
if(a[i+1]+mn[pos]>=md){
l=md+1;
ans=md;
}
else r=md-1;
}
re[i]=r;
}
for(int i=1;i<=n;i++){
int le=a[i]+mn[q];
le=max(le,re[i-1]);
cout<<re[i]-le<<"\n";
}
}
/*
4 3
-2 3 5 8
2
-4
7
*/
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:26:13: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
26 | int ans=0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |