#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define st first
#define nd second
#define f(a, c, b) for (int a = c; b > a; a++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) int(a.size())
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<ll> a(n);
f(i, 0, n) cin >> a[i];
vector<ll> w(q);
f(i, 0, q) cin >> w[i];
ll mksl = 0;
ll mksr = 0;
ll pos = 0;
vector<pair<ll, pair<ll, ll>>> bs = {{0, {0, 0}}};
f(i, 0, q) {
pos += w[i];
if (-pos > mksl) {
mksl = -pos;
bs.pb({mksr + mksl, {mksl, mksr}});
}
if (pos > mksr) {
mksr = pos;
bs.pb({mksr + mksl, {mksl, mksr}});
}
}
/*for (pair<ll, pair<ll, ll>> ele: bs) {
cout << ele.st << " " << ele.nd.st << " " << ele.nd.nd << "\n";
}*/
vector<ll> ans(n, 0);
ans[0] += mksl;
ans.back() += mksr;
f(i, 0, n - 1) {
if ((a[i + 1] - a[i]) >= (mksr + mksl)) {
ans[i] += mksr;
ans[i + 1] += mksl;
}
int l, r, mid;
l = 0;
r = sz(bs) - 2; //chcemy znalelx maksymalnie ind na prawo w ktorym sie zmiescimy
ll odl = a[i + 1] - a[i];
while (r > l) {
mid = (r + l + 1)/2;
if (bs[mid].st <= odl) l = mid;
else r = mid - 1;
}
//cout << "ind " << i << " bs mi skonczyl na " << r << "\n";
ll pl = bs[r + 1].nd.st - bs[r].nd.st;
ll pr = bs[r + 1].nd.nd - bs[r].nd.nd;
ans[i] += bs[r].nd.nd;
ans[i + 1] += bs[r].nd.st;
ll s = bs[r].st;
if (pl) {
ans[i + 1] += (odl - s);
} else {
ans[i] += (odl - s);
}
}
f(i, 0, n) cout << ans[i] << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |