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 int long long
const int mxN = 2e5 + 7;
int arr[mxN], ans[mxN];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q;
cin >> n >> q;
vector<pair<int,int>> dist;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
if (i && abs(arr[i] - arr[i-1])) {
dist.push_back({abs(arr[i] - arr[i-1]), i-1});
}
}
sort(dist.begin(), dist.end(), greater<pair<int,int>>());
int l = 0, r = 0, cur = 0;
for (int i = 0; i < q; ++i) {
int w;
cin >> w;
cur += w;
l = min(l, cur);
r = max(r, cur);
while (dist.size() && abs(l) + r >= dist.back().first) {
auto [d, id] = dist.back();
dist.pop_back();
//cout << d << ' ' << id << ' ' << l << ' ' << r << ' ' << w << '\n';
if (w>=0) {
ans[id] += d-abs(l);
ans[id+1] += abs(l);
}
else {
ans[id+1] += d-r;
ans[id] += r;
}
}
}
ans[0] += abs(l), ans[n-1] += r;
for (int i = 0; i < n; ++i) {
cout << ans[i] << "\n";
}
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:36:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
36 | auto [d, id] = dist.back();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |