#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
vector<long long> v(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
vector<long long> minq(q + 1), maxq(q + 1);
long long sum = 0;
for (int i = 1; i <= q; i++) {
long long x;
cin >> x;
sum += x;
minq[i] = min(minq[i - 1], sum);
maxq[i] = max(maxq[i - 1], sum);
}
vector<long long> ans(n + 1);
for (int i = 1; i < n; i++) {
int s = 1, d = q, pos = 0;
while (s <= d) {
int mid = (s + d) / 2;
if (maxq[mid] + (-minq[mid]) < v[i + 1] - v[i]) {
pos = mid;
s = mid + 1;
} else {
d = mid - 1;
}
}
ans[i] += maxq[pos];
ans[i + 1] += -minq[pos];
if (pos != q) {
if (maxq[pos + 1] > maxq[pos]) {
ans[i] += (v[i + 1] - v[i]) - (maxq[pos] + (-minq[pos]));
}
if (minq[pos + 1] < minq[pos]) {
ans[i + 1] += (v[i + 1] - v[i]) - (maxq[pos] + (-minq[pos]));
}
}
}
ans[1] += -minq[q];
ans[n] += maxq[q];
for (int i = 1; i <= n; i++)
cout << ans[i] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |