#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
const int inf = 2e9;
ll a[N], b[N], mn[N], mx[N], l[N], r[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
ll s = 0;
for (int i = 1; i <= m; i++) {
s += b[i];
mn[i] = min(mn[i - 1], s);
mx[i] = max(mx[i - 1], s);
}
for (int i = 1; i <= n; i++) {
l[i] = a[i] + mn[m];
r[i] = a[i] + mx[m];
}
for (int i = 2; i <= n; i++) {
int lo = 1, hi = m, pos = -1;
while (lo <= hi) {
int mid = lo + hi >> 1;
if (mx[mid] - mn[mid] >= a[i] - a[i - 1]) {
pos = mid;
hi = mid - 1;
}
else lo = mid + 1;
}
if (pos == -1) continue;
if (b[pos] < 0) r[i - 1] = l[i] = a[i - 1] + mx[pos - 1];
else r[i - 1] = l[i] = a[i] + mn[pos - 1];
}
for (int i = 1; i <= n; i++) cout << r[i] - l[i] << en;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:33:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | int mid = lo + hi >> 1;
| ~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
2 ms |
472 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
2 ms |
472 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
27 ms |
7116 KB |
Output is correct |
21 |
Correct |
25 ms |
6960 KB |
Output is correct |
22 |
Correct |
26 ms |
6768 KB |
Output is correct |
23 |
Correct |
24 ms |
6660 KB |
Output is correct |
24 |
Correct |
28 ms |
7292 KB |
Output is correct |
25 |
Correct |
96 ms |
15008 KB |
Output is correct |
26 |
Correct |
102 ms |
14936 KB |
Output is correct |
27 |
Correct |
91 ms |
14540 KB |
Output is correct |
28 |
Correct |
96 ms |
14704 KB |
Output is correct |
29 |
Correct |
99 ms |
14312 KB |
Output is correct |
30 |
Correct |
83 ms |
13632 KB |
Output is correct |
31 |
Correct |
57 ms |
13080 KB |
Output is correct |
32 |
Correct |
60 ms |
13176 KB |
Output is correct |
33 |
Correct |
10 ms |
1860 KB |
Output is correct |
34 |
Correct |
102 ms |
15264 KB |
Output is correct |
35 |
Correct |
96 ms |
14724 KB |
Output is correct |
36 |
Correct |
112 ms |
14952 KB |
Output is correct |
37 |
Correct |
110 ms |
14724 KB |
Output is correct |
38 |
Correct |
100 ms |
14504 KB |
Output is correct |
39 |
Correct |
122 ms |
14748 KB |
Output is correct |
40 |
Correct |
88 ms |
14732 KB |
Output is correct |
41 |
Correct |
35 ms |
7744 KB |
Output is correct |
42 |
Correct |
65 ms |
13188 KB |
Output is correct |
43 |
Correct |
101 ms |
16504 KB |
Output is correct |
44 |
Correct |
32 ms |
7548 KB |
Output is correct |
45 |
Correct |
87 ms |
14676 KB |
Output is correct |
46 |
Correct |
84 ms |
16588 KB |
Output is correct |
47 |
Correct |
97 ms |
16848 KB |
Output is correct |
48 |
Correct |
78 ms |
16868 KB |
Output is correct |