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>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> x(n);
for (auto& el : x)
cin >> el;
vector<int> w(q), wsum(q), curlmax(q), currmax(q);
int cur = 0, wleftmax = 0, wrightmax = 0;
for (int i = 0; i < q; ++i) {
int wi;
cin >> wi;
w[i] = wi;
cur += wi;
if (cur < 0 && wleftmax < abs(cur))
wleftmax = abs(cur);
if (cur > 0 && wrightmax < cur)
wrightmax = cur;
curlmax[i] = wleftmax;
currmax[i] = wrightmax;
wsum[i] = wleftmax + wrightmax;
}
for (int i = 0; i < n; ++i) {
int ans = 0;
if (i == 0) {
ans += wleftmax;
} else if (x[i] - x[i - 1] >= wsum.back()) {
ans += wleftmax;
} else {
int day = lower_bound(wsum.begin(), wsum.end(), x[i] - x[i - 1]) - wsum.begin();
if (w[day] < 0)
ans += (x[i] - x[i - 1]) - currmax[day];
else
ans += curlmax[day];
}
if (i == n - 1) {
ans += wrightmax;
} else if (x[i + 1] - x[i] >= wsum.back()) {
ans += wrightmax;
} else {
int day = lower_bound(wsum.begin(), wsum.end(), x[i + 1] - x[i]) - wsum.begin();
if (w[day] < 0)
ans += currmax[day];
else
ans += (x[i + 1] - x[i]) - curlmax[day];
}
cout << ans << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |