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;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
const long long INF = 1e18;
int main() {
int n, q;
cin >> n >> q;
vector<long long> X(n);
for (auto &v : X) {
cin >> v;
}
X.insert(X.begin(), -INF);
X.insert(X.end(), INF);
min_heap<pair<long long, int>> h;
for (int i = 0; i <= n; i++) {
h.push({X[i + 1] - X[i], i});
}
long long L = 0, R = 0, x = 0;
vector<long long> ans(n + 2);
vector<bool> foundl(n + 2, false), foundr(n + 2, false);
for (int i = 0; i < q; i++) {
long long W;
cin >> W;
x += W;
L = min(L, x);
R = max(R, x);
while (h.top().first <= R - L) {
auto [d, j] = h.top();
h.pop();
long long left = R, right = -L;
if (W > 0)
left = d - right;
if (W < 0)
right = d - left;
ans[j] += left;
ans[j + 1] += right;
foundr[j] = foundl[j + 1] = true;
}
}
for (int i = 1; i <= n; i++) {
if (!foundl[i])
ans[i] -= L;
if (!foundr[i])
ans[i] += R;
cout << ans[i] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |