#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define p_q priority_queue
#define endl '\n'
#define pb push_back
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, q; cin>>n>>q;
vector<int> x(n+2), w(q+2), mx(q+2,0), mn(q+2,0), ans(n+2,0);
for (int i = 1; i <= n; ++i) cin>>x[i];
int cur = 0;
for (int i = 1; i <= q; ++i) {
cin>>w[i];
cur += w[i];
mn[i] = min(mn[i-1],cur);
mx[i] = max(mx[i-1],cur);
}
ans[1] += abs(mn[q]);
ans[n] += mx[q];
for (int i = 2; i <= n; ++i) {
int tmp = x[i]-x[i-1];
int l = 0, r = q+1;
while(r-l > 1) {
int mid = (l+r)>>1;
if (mx[mid]+abs(mn[mid]) <= tmp) l = mid;
else r = mid;
}
ans[i-1] += mx[l];
ans[i] += abs(mn[l]);
if (l == q) continue;
if (w[r] >= 0) ans[i-1] += tmp-mx[l]+mn[l];
else ans[i] += tmp-mx[l]+mn[l];
}
for (int i = 1; i <= n; ++i) cout<<ans[i]<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
544 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
20 ms |
7256 KB |
Output is correct |
21 |
Correct |
18 ms |
7000 KB |
Output is correct |
22 |
Correct |
18 ms |
6744 KB |
Output is correct |
23 |
Correct |
18 ms |
6736 KB |
Output is correct |
24 |
Correct |
22 ms |
7256 KB |
Output is correct |
25 |
Correct |
80 ms |
13532 KB |
Output is correct |
26 |
Correct |
80 ms |
13388 KB |
Output is correct |
27 |
Correct |
77 ms |
13008 KB |
Output is correct |
28 |
Correct |
86 ms |
13248 KB |
Output is correct |
29 |
Correct |
78 ms |
12620 KB |
Output is correct |
30 |
Correct |
74 ms |
12108 KB |
Output is correct |
31 |
Correct |
61 ms |
11604 KB |
Output is correct |
32 |
Correct |
55 ms |
11600 KB |
Output is correct |
33 |
Correct |
7 ms |
1628 KB |
Output is correct |
34 |
Correct |
81 ms |
13900 KB |
Output is correct |
35 |
Correct |
86 ms |
13516 KB |
Output is correct |
36 |
Correct |
80 ms |
13528 KB |
Output is correct |
37 |
Correct |
80 ms |
13136 KB |
Output is correct |
38 |
Correct |
78 ms |
13136 KB |
Output is correct |
39 |
Correct |
85 ms |
13392 KB |
Output is correct |
40 |
Correct |
68 ms |
13392 KB |
Output is correct |
41 |
Correct |
20 ms |
7760 KB |
Output is correct |
42 |
Correct |
56 ms |
11672 KB |
Output is correct |
43 |
Correct |
67 ms |
14928 KB |
Output is correct |
44 |
Correct |
21 ms |
7760 KB |
Output is correct |
45 |
Correct |
60 ms |
13136 KB |
Output is correct |
46 |
Correct |
75 ms |
15596 KB |
Output is correct |
47 |
Correct |
68 ms |
15440 KB |
Output is correct |
48 |
Correct |
68 ms |
15440 KB |
Output is correct |