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>
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];
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |