#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
inline char get_ (){
const int oo=1000005;
static char buf[oo], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, oo, stdin), p1 == p2) ? EOF : *p1 ++;
}
int read_ () {
char c = get_();
int sum = 0;
while(!(c >= '0' && c <= '9')) c = get_();
while(c >= '0' && c <= '9') sum = sum * 10 + (c - '0'), c = get_();
return sum;
}
int n, x[300010], q;
int w[300010];
int ww[300010], we[300010], sw[300010];
int wt[300010];
int32_t main(){
INIT
cin>>n>>q;
for(int i=1; i<=n; i++){
cin>>x[i];
}
int ac=0;
for(int i=1; i<=q; i++){
cin>>w[i];
ww[i]=ww[i-1];
we[i]=we[i-1];
ac+=w[i];
if(ac<0){
ww[i]=max(ww[i], -ac);
}
else{
we[i]=max(we[i], ac);
}
sw[i]=we[i]+ww[i];
}
//dont forget maxwest and maxeast for endpoints
sort(x+1, x+1+n);
for(int i=1; i<n; i++){
//first sw>x[i+1]-x[i];
int l=1, r=q+1, m=(l+r)>>1ll;
while(l<r){
m=(l+r)>>1ll;
if(sw[m]>(x[i+1]-x[i]) ){
r=m;
}
else{
l=(m+1);
}
m=(l+r)>>1ll;
}
wt[i]+=we[m-1];
wt[i+1]+=ww[m-1];
if( (m<=q) ){
if(w[m]<0){
if( sw[m]>(x[i+1]-x[i]) ){wt[i+1]+=x[i+1]-x[i]-we[m-1]-ww[m-1];}
}
else{
if( sw[m]>(x[i+1]-x[i]) ){wt[i]+=x[i+1]-x[i]-ww[m-1]-we[m-1];}
}
}
}
int me=0, mw=0;
ac=0;
for(int i=1; i<=q; i++){
ac+=w[i];
if(ac<0){
mw=max(mw, -ac);
}
else{
me=max(me, ac);
}
}
wt[1]+=mw;
wt[n]+=me;
for(int i=1; i<=n; i++){
cout<<wt[i]<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
416 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
416 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
32 ms |
8768 KB |
Output is correct |
21 |
Correct |
29 ms |
8512 KB |
Output is correct |
22 |
Correct |
29 ms |
8328 KB |
Output is correct |
23 |
Correct |
24 ms |
8144 KB |
Output is correct |
24 |
Correct |
30 ms |
8656 KB |
Output is correct |
25 |
Correct |
98 ms |
15036 KB |
Output is correct |
26 |
Correct |
97 ms |
15072 KB |
Output is correct |
27 |
Correct |
99 ms |
14528 KB |
Output is correct |
28 |
Correct |
95 ms |
14784 KB |
Output is correct |
29 |
Correct |
90 ms |
14284 KB |
Output is correct |
30 |
Correct |
92 ms |
13624 KB |
Output is correct |
31 |
Correct |
60 ms |
12996 KB |
Output is correct |
32 |
Correct |
56 ms |
13252 KB |
Output is correct |
33 |
Correct |
9 ms |
1868 KB |
Output is correct |
34 |
Correct |
101 ms |
15276 KB |
Output is correct |
35 |
Correct |
117 ms |
14792 KB |
Output is correct |
36 |
Correct |
100 ms |
14948 KB |
Output is correct |
37 |
Correct |
95 ms |
14720 KB |
Output is correct |
38 |
Correct |
114 ms |
14532 KB |
Output is correct |
39 |
Correct |
90 ms |
14744 KB |
Output is correct |
40 |
Correct |
66 ms |
14800 KB |
Output is correct |
41 |
Correct |
29 ms |
9240 KB |
Output is correct |
42 |
Correct |
55 ms |
13204 KB |
Output is correct |
43 |
Correct |
72 ms |
16492 KB |
Output is correct |
44 |
Correct |
31 ms |
9172 KB |
Output is correct |
45 |
Correct |
69 ms |
14776 KB |
Output is correct |
46 |
Correct |
88 ms |
16580 KB |
Output is correct |
47 |
Correct |
74 ms |
16796 KB |
Output is correct |
48 |
Correct |
81 ms |
16880 KB |
Output is correct |