#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct state{
ll p,n,cur;
};
int N,Q;
ll X[200001],W[200001],Sum[200001],Ans[200001];
state A[200001];
void debug(){
for (int i=1; i<=Q; i++)
cout<<Sum[i]<<" ";
cout<<"\n\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N>>Q;
for (int i=1; i<=N; i++)
cin>>X[i];
for (int i=1; i<=Q; i++){
cin>>W[i];
A[i]=A[i-1];
A[i].cur+=W[i];
if (A[i].cur>0)
A[i].p=max(A[i].p,A[i].cur);
else
A[i].n=max(A[i].n,-A[i].cur);
Sum[i]=A[i].p+A[i].n;
}
for (int i=1; i<N; i++){
ll len=X[i+1]-X[i];
int t=lower_bound(Sum+1,Sum+Q+1,len)-Sum;
if (t>Q){
Ans[i]+=A[Q].p;
Ans[i+1]+=A[Q].n;
}
else{
if (A[t].p==A[t-1].p){
Ans[i]+=A[t].p;
Ans[i+1]+=len-A[t].p;
}
else{
Ans[i+1]+=A[t].n;
Ans[i]+=len-A[t].n;
}
}
}
Ans[1]+=A[Q].n;
Ans[N]+=A[Q].p;
for (int i=1; i<=N; i++)
cout<<Ans[i]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
564 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
5 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
564 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
5 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
29 ms |
10232 KB |
Output is correct |
21 |
Correct |
29 ms |
10024 KB |
Output is correct |
22 |
Correct |
26 ms |
9896 KB |
Output is correct |
23 |
Correct |
23 ms |
9752 KB |
Output is correct |
24 |
Correct |
30 ms |
10184 KB |
Output is correct |
25 |
Correct |
111 ms |
16520 KB |
Output is correct |
26 |
Correct |
101 ms |
16452 KB |
Output is correct |
27 |
Correct |
93 ms |
16160 KB |
Output is correct |
28 |
Correct |
105 ms |
16360 KB |
Output is correct |
29 |
Correct |
91 ms |
15812 KB |
Output is correct |
30 |
Correct |
82 ms |
15152 KB |
Output is correct |
31 |
Correct |
72 ms |
14648 KB |
Output is correct |
32 |
Correct |
53 ms |
14732 KB |
Output is correct |
33 |
Correct |
9 ms |
1988 KB |
Output is correct |
34 |
Correct |
91 ms |
16836 KB |
Output is correct |
35 |
Correct |
90 ms |
16308 KB |
Output is correct |
36 |
Correct |
94 ms |
16576 KB |
Output is correct |
37 |
Correct |
92 ms |
16324 KB |
Output is correct |
38 |
Correct |
108 ms |
16356 KB |
Output is correct |
39 |
Correct |
87 ms |
16376 KB |
Output is correct |
40 |
Correct |
66 ms |
16356 KB |
Output is correct |
41 |
Correct |
33 ms |
10864 KB |
Output is correct |
42 |
Correct |
65 ms |
14740 KB |
Output is correct |
43 |
Correct |
80 ms |
17988 KB |
Output is correct |
44 |
Correct |
39 ms |
10700 KB |
Output is correct |
45 |
Correct |
60 ms |
16324 KB |
Output is correct |
46 |
Correct |
75 ms |
18132 KB |
Output is correct |
47 |
Correct |
76 ms |
18372 KB |
Output is correct |
48 |
Correct |
79 ms |
18544 KB |
Output is correct |