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 task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define int long long
using namespace std;
const int MAXN = 2e5 + 5;
const ll INF = 1e18 + 5;
int n, q;
ll x[MAXN];
void Input()
{
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> x[i];
}
}
int cs[MAXN], l[MAXN], r[MAXN];
void Solve()
{
x[0] = -INF;
iota(cs + 1, cs + 1 + n, 1);
sort(cs + 1, cs + 1 + n, [](int i, int j)
{
return x[i] - x[i - 1] < x[j] - x[j - 1];
});
int i = 1;
ll cur = 0, maxl = INF, maxr = -INF;
while (q-- > 0)
{
ll w;
cin >> w;
cur += w;
maxr = max(maxr, cur);
maxl = min(maxl, cur);
for (; i <= n && x[cs[i]] - x[cs[i] - 1] <= maxr - maxl; i++)
{
if (w < 0)
{
r[cs[i] - 1] = x[cs[i] - 1] + maxr;
l[cs[i]] = x[cs[i] - 1] + maxr;
} else
{
r[cs[i] - 1] = x[cs[i]] + maxl;
l[cs[i]] = x[cs[i]] + maxl;
}
}
}
for (; i <= n; i++)
{
r[cs[i] - 1] = x[cs[i] - 1] + maxr;
l[cs[i]] = x[cs[i]] + maxl;
}
//r[cs[n]] = x[cs[n]] + maxr;
r[n] = x[n] + maxr;
l[1] = x[1] + maxl;
//cout << r[1] << '\n';
for (int i = 1; i <= n; i++)
{
cout << r[i] - l[i] << '\n';
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
Input();
Solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |