#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,int> ii;
const int N = 2e5;
const ll INF = 1e18;
int n, q;
ll x[N+2], ans[N+2];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
vector<ii> dl, dr;
for (int i = 1; i <= n; i++) {
if (i == 1) dl.push_back({INF,i});
else dl.push_back({x[i]-x[i-1],i});
if (i == n) dr.push_back({INF,i});
else dr.push_back({x[i+1]-x[i],i});
}
sort(dl.begin(),dl.end());
sort(dr.begin(),dr.end());
ll pl = 0, pr = 0, lf = 0, rg = 0, ps = 0;
while (q--) {
ll w; cin >> w;
ps += w;
for (; pl < n && dl[pl].fi <= rg-ps; pl++) {
ans[dl[pl].se] += max(-lf,dl[pl].fi-rg);
}
for (; pr < n && dr[pr].fi <= ps-lf; pr++) {
ans[dr[pr].se] += max(rg,dr[pr].fi+lf);
}
lf = min(lf,ps);
rg = max(rg,ps);
}
for (; pl < n; pl++) ans[dl[pl].se] += -lf;
for (; pr < n; pr++) ans[dr[pr].se] += rg;
for (int i = 1; i <= n; i++) {
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
31 ms |
748 KB |
Output is correct |
21 |
Correct |
28 ms |
748 KB |
Output is correct |
22 |
Correct |
28 ms |
876 KB |
Output is correct |
23 |
Correct |
25 ms |
896 KB |
Output is correct |
24 |
Correct |
35 ms |
2016 KB |
Output is correct |
25 |
Correct |
120 ms |
11972 KB |
Output is correct |
26 |
Correct |
119 ms |
11972 KB |
Output is correct |
27 |
Correct |
119 ms |
11716 KB |
Output is correct |
28 |
Correct |
120 ms |
11844 KB |
Output is correct |
29 |
Correct |
120 ms |
11588 KB |
Output is correct |
30 |
Correct |
126 ms |
11204 KB |
Output is correct |
31 |
Correct |
112 ms |
10820 KB |
Output is correct |
32 |
Correct |
84 ms |
10692 KB |
Output is correct |
33 |
Correct |
16 ms |
2016 KB |
Output is correct |
34 |
Correct |
123 ms |
11972 KB |
Output is correct |
35 |
Correct |
117 ms |
11716 KB |
Output is correct |
36 |
Correct |
119 ms |
11972 KB |
Output is correct |
37 |
Correct |
123 ms |
11332 KB |
Output is correct |
38 |
Correct |
123 ms |
11352 KB |
Output is correct |
39 |
Correct |
129 ms |
11460 KB |
Output is correct |
40 |
Correct |
123 ms |
11508 KB |
Output is correct |
41 |
Correct |
31 ms |
364 KB |
Output is correct |
42 |
Correct |
108 ms |
10308 KB |
Output is correct |
43 |
Correct |
118 ms |
11588 KB |
Output is correct |
44 |
Correct |
33 ms |
364 KB |
Output is correct |
45 |
Correct |
118 ms |
11332 KB |
Output is correct |
46 |
Correct |
109 ms |
11716 KB |
Output is correct |
47 |
Correct |
115 ms |
11716 KB |
Output is correct |
48 |
Correct |
110 ms |
11716 KB |
Output is correct |