#include <bits/stdc++.h>
using namespace std;
// 123
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int64_t> a(n), b(q);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < q; i++) cin >> b[i];
vector<int64_t> mx(q + 1), mn(q + 1), sum(q + 1);
int64_t cur = 0;
for (int i = 0; i < q; i++) {
cur += b[i];
mx[i + 1] = max(mx[i], cur);
mn[i + 1] = min(mn[i], cur);
sum[i + 1] = mx[i + 1] - mn[i + 1];
}
vector<int64_t> res(n);
res[0] -= mn[q];
res[n - 1] += mx[q];
for (int i = 0; i < n - 1; i++) {
int64_t d = a[i + 1] - a[i];
int l = 0, r = q, ans = -1;
while (l <= r) {
int mid = l + r >> 1;
if (sum[mid] > d) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
if (ans == -1) {
res[i] += mx[q];
res[i + 1] -= mn[q];
} else {
assert(ans > 0);
ans--;
res[i] += mx[ans];
res[i + 1] -= mn[ans];
int64_t& which = (b[ans] > 0) ? res[i] : res[i + 1];
which += d - sum[ans];
}
}
for (int i = 0; i < n; i++) cout << res[i] << '\n';
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:28:37: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
22 ms |
8652 KB |
Output is correct |
21 |
Correct |
21 ms |
8396 KB |
Output is correct |
22 |
Correct |
20 ms |
8276 KB |
Output is correct |
23 |
Correct |
28 ms |
8268 KB |
Output is correct |
24 |
Correct |
23 ms |
8648 KB |
Output is correct |
25 |
Correct |
74 ms |
14980 KB |
Output is correct |
26 |
Correct |
87 ms |
14920 KB |
Output is correct |
27 |
Correct |
72 ms |
14644 KB |
Output is correct |
28 |
Correct |
71 ms |
14684 KB |
Output is correct |
29 |
Correct |
76 ms |
14252 KB |
Output is correct |
30 |
Correct |
67 ms |
13588 KB |
Output is correct |
31 |
Correct |
48 ms |
13004 KB |
Output is correct |
32 |
Correct |
42 ms |
13176 KB |
Output is correct |
33 |
Correct |
7 ms |
1876 KB |
Output is correct |
34 |
Correct |
73 ms |
15308 KB |
Output is correct |
35 |
Correct |
76 ms |
14704 KB |
Output is correct |
36 |
Correct |
75 ms |
14960 KB |
Output is correct |
37 |
Correct |
72 ms |
14708 KB |
Output is correct |
38 |
Correct |
71 ms |
14648 KB |
Output is correct |
39 |
Correct |
68 ms |
14932 KB |
Output is correct |
40 |
Correct |
52 ms |
14768 KB |
Output is correct |
41 |
Correct |
23 ms |
9292 KB |
Output is correct |
42 |
Correct |
41 ms |
13132 KB |
Output is correct |
43 |
Correct |
55 ms |
16488 KB |
Output is correct |
44 |
Correct |
21 ms |
9164 KB |
Output is correct |
45 |
Correct |
48 ms |
14668 KB |
Output is correct |
46 |
Correct |
57 ms |
16588 KB |
Output is correct |
47 |
Correct |
57 ms |
16884 KB |
Output is correct |
48 |
Correct |
69 ms |
16972 KB |
Output is correct |