#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;
}
}
if (v.size() == 1) {
for (int i = 1; i <= n; i++) cout << 0 << endl;
return 0;
}
for (int i = 1; i < 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) {
mid = (l+r)/2;
if (a[i]-a[i-1] <= b[mid]) r = mid-1;
else l = mid+1;
}
if (r < 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;
}
/*
10 10
0 1 2 3 4 5 6 7 8 9
0 0 0 0 0 0 0 0 0 0
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 1; i < v.size(); i++) b[i] = abs(v[i-1]-v[i]);
| ~~^~~~~~~~~~
Main.cpp:38:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | if (r < v.size()-1) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
316 KB |
Output is correct |
4 |
Correct |
5 ms |
448 KB |
Output is correct |
5 |
Correct |
5 ms |
352 KB |
Output is correct |
6 |
Correct |
4 ms |
316 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
396 KB |
Output is correct |
10 |
Correct |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
5 ms |
348 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 |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
324 KB |
Output is correct |
17 |
Correct |
5 ms |
448 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
4 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
316 KB |
Output is correct |
4 |
Correct |
5 ms |
448 KB |
Output is correct |
5 |
Correct |
5 ms |
352 KB |
Output is correct |
6 |
Correct |
4 ms |
316 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
396 KB |
Output is correct |
10 |
Correct |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
5 ms |
348 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 |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
324 KB |
Output is correct |
17 |
Correct |
5 ms |
448 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
4 ms |
352 KB |
Output is correct |
20 |
Correct |
82 ms |
4136 KB |
Output is correct |
21 |
Correct |
82 ms |
3900 KB |
Output is correct |
22 |
Correct |
72 ms |
3736 KB |
Output is correct |
23 |
Correct |
68 ms |
3636 KB |
Output is correct |
24 |
Correct |
95 ms |
4020 KB |
Output is correct |
25 |
Correct |
402 ms |
10420 KB |
Output is correct |
26 |
Correct |
404 ms |
10300 KB |
Output is correct |
27 |
Correct |
396 ms |
9868 KB |
Output is correct |
28 |
Correct |
390 ms |
9916 KB |
Output is correct |
29 |
Correct |
391 ms |
8900 KB |
Output is correct |
30 |
Correct |
372 ms |
7372 KB |
Output is correct |
31 |
Correct |
351 ms |
6796 KB |
Output is correct |
32 |
Correct |
360 ms |
6872 KB |
Output is correct |
33 |
Correct |
42 ms |
1312 KB |
Output is correct |
34 |
Correct |
420 ms |
9072 KB |
Output is correct |
35 |
Correct |
426 ms |
8672 KB |
Output is correct |
36 |
Correct |
406 ms |
10332 KB |
Output is correct |
37 |
Correct |
409 ms |
9628 KB |
Output is correct |
38 |
Correct |
397 ms |
9920 KB |
Output is correct |
39 |
Correct |
404 ms |
10180 KB |
Output is correct |
40 |
Correct |
379 ms |
9992 KB |
Output is correct |
41 |
Correct |
94 ms |
3020 KB |
Output is correct |
42 |
Correct |
342 ms |
5356 KB |
Output is correct |
43 |
Correct |
421 ms |
13560 KB |
Output is correct |
44 |
Correct |
99 ms |
6084 KB |
Output is correct |
45 |
Correct |
382 ms |
10040 KB |
Output is correct |
46 |
Correct |
432 ms |
13584 KB |
Output is correct |
47 |
Correct |
436 ms |
10684 KB |
Output is correct |
48 |
Correct |
436 ms |
10840 KB |
Output is correct |