#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,q;
cin >> n >> q;
int pos[n+1];
for(int i=1;i<=n;i++){
cin >> pos[i];
}
int w[q+2];
w[q+1]=0;
w[0]=0;
int x;
int a[q+2];
a[q+1]=(long long)1e18;
a[0]=0;
int mx[q+1];
int mn[q+1];
mn[0]=0;
mx[0]=0;
for(int i=1;i<=q;i++){
cin >> x;
w[i]=w[i-1]+x;
mn[i]=min(mn[i-1],w[i]);
mx[i]=max(mx[i-1],w[i]);
a[i]=mx[i]-mn[i];
}
int ans[n+1];
for(int i=1;i<=n;i++){
ans[i]=0;
}
ans[1]+=(-mn[q]);
for(int i=1;i<n;i++){
int diff=pos[i+1]-pos[i];
int ind=lower_bound(a,a+q+2,diff)-a;
//cout << ind << '\n';
if(ind>q){
ans[i]+=(mx[q]);
ans[i+1]+=(-mn[q]);
}
else{
ind--;
ans[i]+=(mx[ind]);
ans[i+1]+=(-mn[ind]);
if(w[ind+1]<w[ind]){
ans[i+1]+=pos[i+1]-pos[i]-a[ind];
}
else{
ans[i]+=pos[i+1]-pos[i]-a[ind];
}
}
}
ans[n]+=mx[q];
for(int i=1;i<=n;i++){
cout << ans[i] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
372 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
320 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
376 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
372 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
320 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
376 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
27 ms |
8652 KB |
Output is correct |
21 |
Correct |
25 ms |
8396 KB |
Output is correct |
22 |
Correct |
26 ms |
8220 KB |
Output is correct |
23 |
Correct |
22 ms |
8096 KB |
Output is correct |
24 |
Correct |
28 ms |
8632 KB |
Output is correct |
25 |
Correct |
113 ms |
15000 KB |
Output is correct |
26 |
Correct |
90 ms |
14892 KB |
Output is correct |
27 |
Correct |
96 ms |
14500 KB |
Output is correct |
28 |
Correct |
91 ms |
14660 KB |
Output is correct |
29 |
Correct |
92 ms |
14276 KB |
Output is correct |
30 |
Correct |
87 ms |
13632 KB |
Output is correct |
31 |
Correct |
59 ms |
12980 KB |
Output is correct |
32 |
Correct |
55 ms |
13212 KB |
Output is correct |
33 |
Correct |
9 ms |
1740 KB |
Output is correct |
34 |
Correct |
95 ms |
15300 KB |
Output is correct |
35 |
Correct |
87 ms |
14668 KB |
Output is correct |
36 |
Correct |
92 ms |
14908 KB |
Output is correct |
37 |
Correct |
110 ms |
14660 KB |
Output is correct |
38 |
Correct |
93 ms |
14496 KB |
Output is correct |
39 |
Correct |
89 ms |
14772 KB |
Output is correct |
40 |
Correct |
65 ms |
14776 KB |
Output is correct |
41 |
Correct |
27 ms |
9292 KB |
Output is correct |
42 |
Correct |
55 ms |
13116 KB |
Output is correct |
43 |
Correct |
72 ms |
16444 KB |
Output is correct |
44 |
Correct |
30 ms |
9116 KB |
Output is correct |
45 |
Correct |
60 ms |
14640 KB |
Output is correct |
46 |
Correct |
98 ms |
16572 KB |
Output is correct |
47 |
Correct |
82 ms |
16844 KB |
Output is correct |
48 |
Correct |
77 ms |
16972 KB |
Output is correct |