이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |