Submission #868605

#TimeUsernameProblemLanguageResultExecution timeMemory
86860512345678Snowball (JOI21_ho_t2)C++17
100 / 100
166 ms23284 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=2e5+5;
ll n, q, a[nx], h, l, vl, w, ans[nx];
set<tuple<ll, ll, ll>> s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>q;
    for (int i=1; i<=n; i++) cin>>a[i];
    while (q--)
    {
        cin>>w;
        if (vl+w>h) h=vl+w, s.insert(make_tuple(h-l, h, 1));
        if (vl+w<l) l=vl+w, s.insert(make_tuple(h-l, h, 0));
        vl+=w;
    }
    for (int i=1; i<n; i++)
    {
        ll d=a[i+1]-a[i];
        if (d>h-l)
        {
            ans[i]+=h;
            ans[i+1]-=l;
            continue;
        }
        auto [val, ch, t]=*s.lower_bound(make_tuple(d, LLONG_MIN, LLONG_MIN));
        if (t) ans[i+1]+=val-ch, ans[i]+=d-(val-ch);
        else ans[i]+=ch, ans[i+1]+=d-ch;
    }
    ans[1]+=-l;
    ans[n]+=h;
    for (int i=1; i<=n; i++) cout<<ans[i]<<'\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...