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 ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,q,ans[500005],a[500005];
set<pair<ll,ll> >st;
int main(){
ios::sync_with_stdio(false);
cin >> n >> q;
for(int i=1; i<=n; i++){
cin >> a[i];
if(i >= 2){
st.insert(mp(a[i] - a[i - 1] , i));
}
}
ll mn = 0 , mx = 0 , cur = 0;
while(q--){
ll x;
cin >> x;
cur += x;
ll bef = cur;
mx = max(mx , cur);
mn = min(mn , cur);
while(st.size() && abs(mx) + abs(mn) >= (*st.begin()).f){
ll i = (*st.begin()).s;
st.erase(st.begin());
if(bef == mx){
ans[i] += abs(mn);
ans[i - 1] += a[i] - a[i - 1] - abs(mn);
}
else {
ans[i - 1] += mx;
ans[i] += a[i] - a[i - 1] - mx;
}
}
}
while(st.size()){
ll i = (*st.begin()).s;
st.erase(st.begin());
ans[i] += abs(mn);
ans[i - 1] += mx;
}
ans[1] += abs(mn);
ans[n] += abs(mx);
for(int i=1; i<=n; i++)
cout << ans[i] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |