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;
using ll = long long;
#define dbg(x) cerr << #x << ": " << x << endl;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<ll> a(n);
for (auto& x : a) {
cin >> x;
}
ll max_value = 0;
ll min_value = 0;
ll curr_value = 0;
vector<ll> ans(n);
vector<ll> space(n - 1);
for (int i = 0; i < n - 1; ++i) {
space[i] = a[i + 1] - a[i];
}
while (q--) {
ll w;
cin >> w;
curr_value += w;
if (w > 0) {
if (curr_value <= max_value) continue;
ll d = curr_value - max_value;
max_value = max(max_value, curr_value);
ans[n - 1] += d;
for (int i = 0; i < n - 1; ++i) {
ll r = min(d, space[i]);
space[i] -= r;
ans[i] += r;
}
} else {
if (curr_value >= min_value) continue;
ll d = min_value - curr_value;
min_value = min(min_value, curr_value);
ans[0] += d;
for (int i = 1; i < n; ++i) {
ll r = min(d, space[i - 1]);
space[i - 1] -= r;
ans[i] += r;
}
}
}
for (auto x : ans) {
cout << x << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |