Submission #373941

#TimeUsernameProblemLanguageResultExecution timeMemory
373941achibasadzishviliSnowball (JOI21_ho_t2)C++17
100 / 100
258 ms17772 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...