#include <bits/stdc++.h>
#define uwu return 0;
using namespace std;
const int SIZE = 2e5 + 5;
int N, Q;
const long long INF = 3e18 + 5;
long long L[SIZE], R[SIZE], W[SIZE], X[SIZE];
#define fs first
#define sc second
int main(){
cin >> N >> Q;
X[N + 1] = INF;
X[0] = -INF;
for (int i = 1; i <= N;i++){
cin >> X[i];
W[i] = 0;
}
long long in_W, mnL = 0, mxR = 0, nX = 0;
multiset <pair<long long, long long>> opW;
opW.insert({0, 0});
for (int i = 1; i <= Q;i++){
cin >> in_W;
nX += in_W;
mnL = min(nX, mnL);
mxR = max(nX, mxR);
opW.insert({mxR - mnL, mxR});
}
/*
for(auto i:opW){
cout << i.fs << ' ' << i.sc << '\n';
}
*/
pair<long long, long long> tmp, pretmp;
W[1] += -mnL;
W[N] += mxR;
long long L, R;
for (int i = 1; i < N;i++){
tmp = *opW.lower_bound({X[i + 1] - X[i], 0LL});
pretmp = *prev(opW.lower_bound({X[i + 1] - X[i], 0LL}));
if(opW.lower_bound({X[i + 1] - X[i], 0LL}) == opW.end()){
tmp = {mxR - mnL, mxR};
}
L = pretmp.fs - pretmp.sc;
R = tmp.sc;
W[i] += min(min(R, X[i + 1] - X[i] - L), mxR);
W[i + 1] += min(max(L, X[i + 1] - X[i] - R), -mnL);
//cout << W[i] << ' ' << W[i + 1] << ' ' << min(R, X[i + 1] - X[i] - L) << '\n';
}
for (int i = 1; i <= N;i++){
cout << W[i] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2904 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2496 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2904 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2396 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2496 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
94 ms |
14896 KB |
Output is correct |
21 |
Correct |
90 ms |
14932 KB |
Output is correct |
22 |
Correct |
93 ms |
15188 KB |
Output is correct |
23 |
Correct |
84 ms |
14992 KB |
Output is correct |
24 |
Correct |
97 ms |
16724 KB |
Output is correct |
25 |
Correct |
277 ms |
22188 KB |
Output is correct |
26 |
Correct |
281 ms |
22344 KB |
Output is correct |
27 |
Correct |
267 ms |
22144 KB |
Output is correct |
28 |
Correct |
284 ms |
22084 KB |
Output is correct |
29 |
Correct |
274 ms |
21588 KB |
Output is correct |
30 |
Correct |
250 ms |
21328 KB |
Output is correct |
31 |
Correct |
163 ms |
20568 KB |
Output is correct |
32 |
Correct |
163 ms |
20548 KB |
Output is correct |
33 |
Correct |
23 ms |
4404 KB |
Output is correct |
34 |
Correct |
281 ms |
22608 KB |
Output is correct |
35 |
Correct |
272 ms |
22096 KB |
Output is correct |
36 |
Correct |
275 ms |
22328 KB |
Output is correct |
37 |
Correct |
284 ms |
22100 KB |
Output is correct |
38 |
Correct |
287 ms |
22096 KB |
Output is correct |
39 |
Correct |
256 ms |
22100 KB |
Output is correct |
40 |
Correct |
186 ms |
22084 KB |
Output is correct |
41 |
Correct |
106 ms |
17748 KB |
Output is correct |
42 |
Correct |
191 ms |
20676 KB |
Output is correct |
43 |
Correct |
220 ms |
23848 KB |
Output is correct |
44 |
Correct |
103 ms |
17488 KB |
Output is correct |
45 |
Correct |
203 ms |
22036 KB |
Output is correct |
46 |
Correct |
217 ms |
24112 KB |
Output is correct |
47 |
Correct |
222 ms |
24136 KB |
Output is correct |
48 |
Correct |
219 ms |
24144 KB |
Output is correct |