#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;
while (pl < n && dl[pl].fi <= rg-ps) {
ans[dl[pl].se] += max(-lf,dl[pl].fi-rg);
pl++;
}
while (pr < n && dr[pr].fi <= ps-lf) {
ans[dr[pr].se] += max(rg,dr[pr].fi+lf);
pr++;
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
3 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 |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
3 ms |
448 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 |
492 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
3 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 |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
3 ms |
448 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 |
492 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 |
30 ms |
2540 KB |
Output is correct |
21 |
Correct |
29 ms |
2284 KB |
Output is correct |
22 |
Correct |
28 ms |
2156 KB |
Output is correct |
23 |
Correct |
27 ms |
2156 KB |
Output is correct |
24 |
Correct |
34 ms |
3296 KB |
Output is correct |
25 |
Correct |
125 ms |
15300 KB |
Output is correct |
26 |
Correct |
124 ms |
15172 KB |
Output is correct |
27 |
Correct |
119 ms |
15044 KB |
Output is correct |
28 |
Correct |
125 ms |
15044 KB |
Output is correct |
29 |
Correct |
121 ms |
14680 KB |
Output is correct |
30 |
Correct |
123 ms |
13892 KB |
Output is correct |
31 |
Correct |
114 ms |
13380 KB |
Output is correct |
32 |
Correct |
85 ms |
13508 KB |
Output is correct |
33 |
Correct |
13 ms |
2144 KB |
Output is correct |
34 |
Correct |
123 ms |
15636 KB |
Output is correct |
35 |
Correct |
121 ms |
15172 KB |
Output is correct |
36 |
Correct |
121 ms |
15300 KB |
Output is correct |
37 |
Correct |
126 ms |
15172 KB |
Output is correct |
38 |
Correct |
142 ms |
15044 KB |
Output is correct |
39 |
Correct |
126 ms |
15044 KB |
Output is correct |
40 |
Correct |
124 ms |
15044 KB |
Output is correct |
41 |
Correct |
32 ms |
3052 KB |
Output is correct |
42 |
Correct |
131 ms |
13508 KB |
Output is correct |
43 |
Correct |
126 ms |
16836 KB |
Output is correct |
44 |
Correct |
33 ms |
2924 KB |
Output is correct |
45 |
Correct |
119 ms |
15044 KB |
Output is correct |
46 |
Correct |
114 ms |
16964 KB |
Output is correct |
47 |
Correct |
114 ms |
17288 KB |
Output is correct |
48 |
Correct |
113 ms |
17220 KB |
Output is correct |