#include <iostream>
#include <vector>
using namespace std;
long long n, test, a[200010], cur, x, minn, maxx, b[200010], l, r, mid, ans[200010];
vector<long long> v;
int main() {
cin >> n >> test;
for (int i = 1; i <= n; i++) cin >> a[i];
v.push_back(0);
while (test--) {
cin >> x;
cur += x;
if (cur > maxx) {
if (v.back() <= 0) v.push_back(cur);
else v.back() = cur;
maxx = cur;
} else if (cur < minn) {
if (v.back() >= 0) v.push_back(cur);
else v.back() = cur;
minn = cur;
}
}
for (int i = 1; i < (int)v.size(); i++) b[i] = abs(v[i-1]-v[i]);
ans[1] -= minn;
for (int i = 2; i <= n; i++) {
l = 1; r = v.size()-1;
while (l <= r) {
int mid = (l+r)/2;
if (a[i]-a[i-1] <= b[mid]) r = mid-1;
else l = mid+1;
}
if (r < (int)v.size()-1) {
r++;
if (v[r-1] < 0) ans[i] -= max(a[i-1]-a[i],v[r-1]);
else ans[i-1] += min(a[i]-a[i-1],v[r-1]);
if (v[r] < 0) ans[i] -= max(a[i-1]+min(a[i]-a[i-1],v[r-1])-a[i],v[r]);
else ans[i-1] += min(a[i]+max(a[i-1]-a[i],v[r-1])-a[i-1],v[r]);
} else {
if (v[r-1] < 0) ans[i] -= max(a[i-1]-a[i],v[r-1]);
else ans[i-1] += min(a[i]-a[i-1],v[r-1]);
if (v[r] < 0) ans[i] -= max(a[i-1]+min(a[i]-a[i-1],v[r-1])-a[i],v[r]);
else ans[i-1] += min(a[i]+max(a[i-1]-a[i],v[r-1])-a[i-1],v[r]);
}
}
ans[n] += maxx;
for (int i = 1; i <= n; i++) cout << ans[i] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
5 ms |
380 KB |
Output is correct |
16 |
Correct |
5 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
5 ms |
380 KB |
Output is correct |
16 |
Correct |
5 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |