#include <bits/stdc++.h>
#define int int64_t
using namespace std;
constexpr static int MXSIZE = 2e5;
constexpr static int MXLOG = 30;
int mnpr[MXSIZE+1], mxpr[MXSIZE+1], n, q, v[MXSIZE], d[MXSIZE], res[MXSIZE];
int32_t main()
{
cin >> n >> q;
for (int i = 0; i < n; i++)
cin >> v[i];
for (int i = 0; i < q; i++)
cin >> d[i];
for (int i = 1; i < q; i++)
d[i] += d[i-1];
for (int i = 1; i <= q; i++)
mnpr[i] = mxpr[i] = d[i-1];
for (int i = 1; i <= q; i++)
{
mnpr[i] = min(mnpr[i], mnpr[i-1]);
mxpr[i] = max(mxpr[i], mxpr[i-1]);
}
#ifdef DEBUGGING
for (int i = 0; i <= q; i++)
cout << mnpr[i] << " ";
cout << "\n";
for (int i = 0; i <= q; i++)
cout << mxpr[i] << " ";
cout <<"\n";
#endif
res[0] = -mnpr[q];
for (int i = 1; i < n; i++)
{
int diff = v[i] - v[i-1];
int l = -1, r = q+1;
while (r - l > 1)
{
int m = l+r>>1;
if (mxpr[m] - mnpr[m] > diff)
r = m;
else
l = m;
}
if (r == q+1)
{
res[i-1] += mxpr[l];
res[i] += -mnpr[l];
}
else
{
res[i-1] += min(mxpr[r], diff + mnpr[l]);
res[i] += min(-mnpr[r], diff - mxpr[l]);
}
}
res[n-1] += mxpr[q];
for (int i = 0; i < n; i++)
cout << res[i] << "\n";
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:41:34: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
41 | int m = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
448 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
448 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
66 ms |
7124 KB |
Output is correct |
21 |
Correct |
58 ms |
6896 KB |
Output is correct |
22 |
Correct |
54 ms |
6656 KB |
Output is correct |
23 |
Correct |
51 ms |
6556 KB |
Output is correct |
24 |
Correct |
65 ms |
7104 KB |
Output is correct |
25 |
Correct |
152 ms |
13388 KB |
Output is correct |
26 |
Correct |
159 ms |
13240 KB |
Output is correct |
27 |
Correct |
151 ms |
13092 KB |
Output is correct |
28 |
Correct |
153 ms |
13192 KB |
Output is correct |
29 |
Correct |
146 ms |
12700 KB |
Output is correct |
30 |
Correct |
138 ms |
11984 KB |
Output is correct |
31 |
Correct |
119 ms |
11436 KB |
Output is correct |
32 |
Correct |
132 ms |
11636 KB |
Output is correct |
33 |
Correct |
15 ms |
1700 KB |
Output is correct |
34 |
Correct |
161 ms |
13704 KB |
Output is correct |
35 |
Correct |
169 ms |
13152 KB |
Output is correct |
36 |
Correct |
149 ms |
13324 KB |
Output is correct |
37 |
Correct |
152 ms |
13096 KB |
Output is correct |
38 |
Correct |
153 ms |
12932 KB |
Output is correct |
39 |
Correct |
160 ms |
13152 KB |
Output is correct |
40 |
Correct |
138 ms |
13156 KB |
Output is correct |
41 |
Correct |
74 ms |
7632 KB |
Output is correct |
42 |
Correct |
117 ms |
11588 KB |
Output is correct |
43 |
Correct |
173 ms |
14888 KB |
Output is correct |
44 |
Correct |
74 ms |
7584 KB |
Output is correct |
45 |
Correct |
138 ms |
13188 KB |
Output is correct |
46 |
Correct |
171 ms |
15052 KB |
Output is correct |
47 |
Correct |
175 ms |
15268 KB |
Output is correct |
48 |
Correct |
194 ms |
15276 KB |
Output is correct |