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
#define x first
#define y second
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> q;
vector<int> a(n + 1);
vector<pair<int, int>> ord;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(i > 1) {
ord.emplace_back(a[i] - a[i - 1], i);
}
}
sort(ord.begin(), ord.end());
int sum = 0, l = 0, r = 0;
int p = 0;
vector<int> ans(n + 1);
while(q--) {
int w;
cin >> w;
sum += w;
if(r < sum) {
r = sum;
while(p < n - 1 && ord[p].x < -l + r) {
ans[ord[p].y] += (-l);
ans[ord[p].y - 1] += ord[p].x - (-l);
p++;
}
}
if(l > sum) {
l = sum;
while(p < n - 1 && ord[p].x < -l + r) {
ans[ord[p].y - 1] += r;
ans[ord[p].y] += ord[p].x - r;
p++;
}
}
}
ans[1] += (-l);
ans[n] += r;
for(int i = p; i < (int)ord.size(); i++) {
ans[ord[i].y - 1] += r;
ans[ord[i].y] += (-l);
}
for(int i = 1; i <= n; i++) {
cout << ans[i] << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |