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 For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define INF (1000000000000000ll);
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;
int mx[200020];
int mn[200020];
int x[200020];
int w[200020];
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0);
// nachoneko sama & miku sama bless me >/////<
int n,q; cin>>n>>q;
For(i,1,n) cin>>x[i];
int now=0;
For(i,1,q){
int t; cin>>t;
now+=t;
mx[i]=max(mx[i-1],now);
mn[i]=min(mn[i-1],now);
}
w[1]-=mn[q];
w[n]+=mx[q];
For(i,1,n-1){
int d=x[i+1]-x[i];
if(d>mx[q]-mn[q]){
w[i]+=mx[q];
w[i+1]-=mn[q];
continue;
}
int hi=q,lo=0;
while(hi-lo>1){
int mi=(hi+lo)/2;
if(mx[mi]-mn[mi]>=d) hi=mi;
else lo=mi;
}
w[i]+=mx[lo];
w[i+1]-=mn[lo];
d-=mx[lo]-mn[lo];
if(mx[hi]>mx[lo]) w[i]+=d;
else if(mn[hi]<mn[lo]) w[i+1]+=d;
else assert(false);
}
For(i,1,n) cout<<w[i]<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |