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;
void solve() {
int n, q;
cin >> n >> q;
vector<long long> x(n);
for (int i = 0; i < n; ++i) {
cin >> x[i];
}
vector<long long> w(q), pr(q + 1), pr_mn(q + 1), pr_mx(q + 1);
for (int i = 0; i < q; ++i) {
cin >> w[i];
pr[i + 1] = pr[i] + w[i];
pr_mn[i + 1] = min(pr_mn[i], pr[i + 1]);
pr_mx[i + 1] = max(pr_mx[i], pr[i + 1]);
}
vector<long long> ans(n);
for (int i = 0; i < n - 1; ++i) {
int l = 0, r = q + 1;
while (l < r - 1) {
int m = (l + r) / 2;
if (pr_mx[m] - pr_mn[m] >= x[i + 1] - x[i]) {
r = m;
} else {
l = m;
}
}
if (r == q + 1) {
ans[i] += pr_mx[q];
ans[i + 1] -= pr_mn[q];
} else if (pr[r] > pr[l]) {
ans[i + 1] -= pr_mn[r];
ans[i] += x[i + 1] - x[i] + pr_mn[r];
} else {
ans[i] += pr_mx[r];
ans[i + 1] += x[i + 1] - x[i] - pr_mx[r];
}
}
ans[0] -= pr_mn[q];
ans[n - 1] += pr_mx[q];
for (int i = 0; i < n; ++i) {
cout << ans[i] << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |