#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,a[N],n,m,ans[N];
set<pair<int,int> > s;
main(){
// t=1;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i-1) s.insert({-a[i]+a[i-1],i-1});
}
int cur = 0, mxR = 0, mxL = 0;
for(int i=1;i<=m;i++){
int w;
cin >> w;
cur+=w; //cout<<mxL<<" "<<mxR<<endl;
if(mxR < cur){
mxR = cur ;
while(s.upper_bound({mxL-mxR,0})!=s.end()){
int c = (*s.upper_bound({mxL-mxR,0})).s;
// cout<<"++"<<c<<" "<<a[c+1]-a[c]+mxL<<endl;
s.erase(s.upper_bound({mxL-mxR,0}));
ans[c+1] += -mxL;
ans[c] += a[c+1]-a[c]+mxL;
}
}
if(mxL > cur) {
mxL = cur ;
while(s.upper_bound({mxL-mxR,0})!=s.end()){
int c = (*s.upper_bound({mxL-mxR,0})).s;
// cout<<"++"<<c<<" " <<mxR<<endl;
s.erase(s.upper_bound({mxL-mxR,0}));
ans[c] += mxR;
ans[c+1] += a[c+1]-a[c]-mxR;
}
}
}
ans[1]-=mxL;
ans[n]+=mxR;
while(s.size()){
int c = (*s.begin()).s;
ans[c] += mxR;
ans[c+1] += -mxL;
s.erase(*s.begin());
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
}
Compilation message
Main.cpp:9:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
3 ms |
460 KB |
Output is correct |
11 |
Correct |
3 ms |
452 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
4 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
460 KB |
Output is correct |
7 |
Correct |
3 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
3 ms |
460 KB |
Output is correct |
11 |
Correct |
3 ms |
452 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
4 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
94 ms |
2324 KB |
Output is correct |
21 |
Correct |
89 ms |
2116 KB |
Output is correct |
22 |
Correct |
84 ms |
1956 KB |
Output is correct |
23 |
Correct |
80 ms |
1964 KB |
Output is correct |
24 |
Correct |
107 ms |
3752 KB |
Output is correct |
25 |
Correct |
497 ms |
21208 KB |
Output is correct |
26 |
Correct |
396 ms |
21204 KB |
Output is correct |
27 |
Correct |
398 ms |
20804 KB |
Output is correct |
28 |
Correct |
407 ms |
20932 KB |
Output is correct |
29 |
Correct |
401 ms |
20476 KB |
Output is correct |
30 |
Correct |
361 ms |
19892 KB |
Output is correct |
31 |
Correct |
284 ms |
19268 KB |
Output is correct |
32 |
Correct |
275 ms |
19576 KB |
Output is correct |
33 |
Correct |
31 ms |
2392 KB |
Output is correct |
34 |
Correct |
450 ms |
21560 KB |
Output is correct |
35 |
Correct |
402 ms |
20924 KB |
Output is correct |
36 |
Correct |
424 ms |
21236 KB |
Output is correct |
37 |
Correct |
403 ms |
20980 KB |
Output is correct |
38 |
Correct |
423 ms |
20828 KB |
Output is correct |
39 |
Correct |
376 ms |
21060 KB |
Output is correct |
40 |
Correct |
346 ms |
21004 KB |
Output is correct |
41 |
Correct |
110 ms |
3012 KB |
Output is correct |
42 |
Correct |
325 ms |
19432 KB |
Output is correct |
43 |
Correct |
330 ms |
22788 KB |
Output is correct |
44 |
Correct |
116 ms |
2852 KB |
Output is correct |
45 |
Correct |
366 ms |
20968 KB |
Output is correct |
46 |
Correct |
340 ms |
22920 KB |
Output is correct |
47 |
Correct |
345 ms |
23116 KB |
Output is correct |
48 |
Correct |
353 ms |
23116 KB |
Output is correct |