#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, q; cin >> n >> q;
int x[n]; for(int &i : x) cin >> i;
int w[q]; for(int &i : w) cin >> i;
int a[q], b[q];
a[0] = max(w[0], 0LL);
b[0] = min(w[0], 0LL);
for(int i=1; i<q; ++i){
w[i] += w[i-1];
a[i] = max(a[i-1], w[i]);
b[i] = min(b[i-1], w[i]);
}
for(int &i : b) i = -i;
int l[n], r[n];
fill(l, l+n, 0LL);
fill(r, r+n, 0LL);
for(int i=0; i+1<n; ++i){
int mx = 0, diff = x[i+1] - x[i];
if(a[0] + b[0] >= diff){
r[i] = min(diff, a[0]);
l[i+1] = min(diff, b[0]);
continue;
}
for(int y=q/2; y; y/=2)
while(mx+y < q and a[mx+y] + b[mx+y] < diff) mx += y;
r[i] = a[mx];
l[i+1] = b[mx];
++mx;
if(mx < q){
l[i+1] = min(diff - a[mx-1], b[mx]);
r[i] = min(diff - b[mx-1], a[mx]);
}
}
l[0] = b[q-1];
r[n-1] = a[q-1];
for(int i=0; i<n; ++i) cout << l[i] + r[i] nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
408 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
408 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
31 ms |
4932 KB |
Output is correct |
21 |
Correct |
30 ms |
4904 KB |
Output is correct |
22 |
Correct |
29 ms |
4968 KB |
Output is correct |
23 |
Correct |
26 ms |
5004 KB |
Output is correct |
24 |
Correct |
33 ms |
5580 KB |
Output is correct |
25 |
Correct |
113 ms |
11232 KB |
Output is correct |
26 |
Correct |
113 ms |
11164 KB |
Output is correct |
27 |
Correct |
112 ms |
11076 KB |
Output is correct |
28 |
Correct |
113 ms |
11080 KB |
Output is correct |
29 |
Correct |
109 ms |
10800 KB |
Output is correct |
30 |
Correct |
105 ms |
10384 KB |
Output is correct |
31 |
Correct |
83 ms |
10148 KB |
Output is correct |
32 |
Correct |
77 ms |
10032 KB |
Output is correct |
33 |
Correct |
11 ms |
1356 KB |
Output is correct |
34 |
Correct |
114 ms |
11236 KB |
Output is correct |
35 |
Correct |
112 ms |
10964 KB |
Output is correct |
36 |
Correct |
113 ms |
11344 KB |
Output is correct |
37 |
Correct |
116 ms |
11024 KB |
Output is correct |
38 |
Correct |
109 ms |
10960 KB |
Output is correct |
39 |
Correct |
112 ms |
10972 KB |
Output is correct |
40 |
Correct |
90 ms |
11076 KB |
Output is correct |
41 |
Correct |
32 ms |
4876 KB |
Output is correct |
42 |
Correct |
67 ms |
10052 KB |
Output is correct |
43 |
Correct |
82 ms |
11240 KB |
Output is correct |
44 |
Correct |
33 ms |
4864 KB |
Output is correct |
45 |
Correct |
77 ms |
11080 KB |
Output is correct |
46 |
Correct |
86 ms |
11316 KB |
Output is correct |
47 |
Correct |
87 ms |
11356 KB |
Output is correct |
48 |
Correct |
87 ms |
11332 KB |
Output is correct |