#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
vector <int> a(n+2),re(n+1);
for(int i=1;i<=n;i++)cin>>a[i];
a[n+1]=1e18;a[0]=-1e18;
re[0]=-1e18;
vector <int> x(q+1),mn(q+1),mx(q+1);
for(int i=1;i<=q;i++){
cin>>x[i];
x[i]+=x[i-1];
mn[i]=min(mn[i-1],x[i]);
mx[i]=max(mx[i-1],x[i]);
}
for(int i=1;i<=n;i++){
int l=a[i],r=min(a[i+1],a[i]+mx[q]);
int ans=0;
while(l<=r){
int md=(l+r)/2;
auto pos=lower_bound(all(mx),md-a[i])-mx.begin();
if(a[i+1]+mn[pos]>=md){
l=md+1;
ans=md;
}
else r=md-1;
}
re[i]=r;
}
for(int i=1;i<=n;i++){
int le=a[i]+mn[q];
le=max(le,re[i-1]);
cout<<re[i]-le<<"\n";
}
}
/*
4 3
-2 3 5 8
2
-4
7
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:26:13: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
26 | int ans=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
500 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
500 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
64 ms |
7508 KB |
Output is correct |
21 |
Correct |
56 ms |
6996 KB |
Output is correct |
22 |
Correct |
53 ms |
6768 KB |
Output is correct |
23 |
Correct |
53 ms |
6668 KB |
Output is correct |
24 |
Correct |
89 ms |
6996 KB |
Output is correct |
25 |
Correct |
481 ms |
13540 KB |
Output is correct |
26 |
Correct |
468 ms |
13456 KB |
Output is correct |
27 |
Correct |
436 ms |
13140 KB |
Output is correct |
28 |
Correct |
426 ms |
13132 KB |
Output is correct |
29 |
Correct |
397 ms |
12648 KB |
Output is correct |
30 |
Correct |
230 ms |
12112 KB |
Output is correct |
31 |
Correct |
112 ms |
11468 KB |
Output is correct |
32 |
Correct |
134 ms |
11604 KB |
Output is correct |
33 |
Correct |
40 ms |
1624 KB |
Output is correct |
34 |
Correct |
437 ms |
13856 KB |
Output is correct |
35 |
Correct |
422 ms |
13284 KB |
Output is correct |
36 |
Correct |
492 ms |
13612 KB |
Output is correct |
37 |
Correct |
444 ms |
13136 KB |
Output is correct |
38 |
Correct |
450 ms |
13144 KB |
Output is correct |
39 |
Correct |
437 ms |
13248 KB |
Output is correct |
40 |
Correct |
206 ms |
13344 KB |
Output is correct |
41 |
Correct |
73 ms |
7892 KB |
Output is correct |
42 |
Correct |
111 ms |
11596 KB |
Output is correct |
43 |
Correct |
205 ms |
14944 KB |
Output is correct |
44 |
Correct |
72 ms |
7660 KB |
Output is correct |
45 |
Correct |
185 ms |
13136 KB |
Output is correct |
46 |
Correct |
209 ms |
15208 KB |
Output is correct |
47 |
Correct |
213 ms |
15276 KB |
Output is correct |
48 |
Correct |
162 ms |
15460 KB |
Output is correct |