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;
typedef long long ll;
ll lr[200001][2];
priority_queue<pair<ll, ll>> pq;
int main() {
int n, q;
ll x, xt, w, cu = 0, ml = 0, mr = 0;
cin >> n >> q;
cin >> xt;
for (int i = 1; i < n; i++) {
cin >> x;
pq.push(make_pair(xt - x, i));
xt = x;
}
for (int i = 0; i < q; i++) {
cin >> w;
cu += w;
if (cu < ml) {
ml = cu;
while (!pq.empty() && -pq.top().first <= mr - ml) {
lr[pq.top().second][0] = -pq.top().first - mr;
lr[pq.top().second - 1][1] = mr;
pq.pop();
}
}
if (cu > mr) {
mr = cu;
while (!pq.empty() && -pq.top().first < mr - ml) {
lr[pq.top().second][0] = -ml;
lr[pq.top().second - 1][1] = ml - pq.top().first;
pq.pop();
}
}
}
while (!pq.empty()) {
lr[pq.top().second][0] = -ml;
lr[pq.top().second - 1][1] = mr;
pq.pop();
}
lr[0][0] = -ml;
lr[n - 1][1] = mr;
for (int i = 0; i < n; i++) {
cout << lr[i][0] + lr[i][1] << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |