#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define x first
#define y second
#define elif else if
//#define endl '\n'
#define all(x) begin(x), end(x)
ll n,q,cur,w,day;
ll x[200069],ans[200069],minimum,maximum;
pair<ll,ll> interval[200069];
ll range[200069];
bool dir[200069];//true for right, false for left;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>q;
for (int i = 0; i < n; i++) {
cin>>x[i];
}
for (int i = 0; i < q; i++) {
cin>>w;
cur+=w;
minimum=min(minimum,cur);
maximum=max(maximum,cur);
interval[i]={minimum,maximum};
range[i]=maximum-minimum;
dir[i]=(cur>0);
}
ans[0]-=minimum;
ans[n-1]+=maximum;
for (int i = 0; i < n-1; i++) {
day=lower_bound(range,range+q,x[i+1]-x[i])-range;
if (day==q) {
ans[i]+=maximum;
ans[i+1]-=minimum;
}
else{
if (dir[day]) {
ans[i+1]-=max(interval[day].f,x[i]-x[i+1]);
ans[i]+=max(x[i+1]-x[i]+interval[day].f,(ll)0);
}
else{
ans[i]+=min(interval[day].s,x[i+1]-x[i]);
ans[i+1]+=max(x[i+1]-x[i]-interval[day].s,(ll)0);
}
}
}
for (int i = 0; i < n; i++) {
cout<<ans[i]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
6 ms |
492 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
6 ms |
492 KB |
Output is correct |
8 |
Correct |
5 ms |
492 KB |
Output is correct |
9 |
Correct |
6 ms |
492 KB |
Output is correct |
10 |
Correct |
5 ms |
492 KB |
Output is correct |
11 |
Correct |
5 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
6 ms |
492 KB |
Output is correct |
16 |
Correct |
6 ms |
492 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
6 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
6 ms |
492 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
6 ms |
492 KB |
Output is correct |
8 |
Correct |
5 ms |
492 KB |
Output is correct |
9 |
Correct |
6 ms |
492 KB |
Output is correct |
10 |
Correct |
5 ms |
492 KB |
Output is correct |
11 |
Correct |
5 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
6 ms |
492 KB |
Output is correct |
16 |
Correct |
6 ms |
492 KB |
Output is correct |
17 |
Correct |
6 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
6 ms |
492 KB |
Output is correct |
20 |
Correct |
32 ms |
7404 KB |
Output is correct |
21 |
Correct |
30 ms |
7168 KB |
Output is correct |
22 |
Correct |
32 ms |
7020 KB |
Output is correct |
23 |
Correct |
32 ms |
6892 KB |
Output is correct |
24 |
Correct |
75 ms |
7404 KB |
Output is correct |
25 |
Correct |
529 ms |
13420 KB |
Output is correct |
26 |
Correct |
526 ms |
13420 KB |
Output is correct |
27 |
Correct |
519 ms |
13164 KB |
Output is correct |
28 |
Correct |
526 ms |
13628 KB |
Output is correct |
29 |
Correct |
517 ms |
13008 KB |
Output is correct |
30 |
Correct |
518 ms |
12276 KB |
Output is correct |
31 |
Correct |
483 ms |
11884 KB |
Output is correct |
32 |
Correct |
488 ms |
11884 KB |
Output is correct |
33 |
Correct |
51 ms |
1900 KB |
Output is correct |
34 |
Correct |
523 ms |
13548 KB |
Output is correct |
35 |
Correct |
519 ms |
13272 KB |
Output is correct |
36 |
Correct |
521 ms |
13480 KB |
Output is correct |
37 |
Correct |
521 ms |
13292 KB |
Output is correct |
38 |
Correct |
519 ms |
13164 KB |
Output is correct |
39 |
Correct |
523 ms |
13328 KB |
Output is correct |
40 |
Correct |
497 ms |
13420 KB |
Output is correct |
41 |
Correct |
34 ms |
7916 KB |
Output is correct |
42 |
Correct |
481 ms |
11976 KB |
Output is correct |
43 |
Correct |
498 ms |
13420 KB |
Output is correct |
44 |
Correct |
34 ms |
7916 KB |
Output is correct |
45 |
Correct |
497 ms |
13292 KB |
Output is correct |
46 |
Correct |
511 ms |
13676 KB |
Output is correct |
47 |
Correct |
510 ms |
13548 KB |
Output is correct |
48 |
Correct |
509 ms |
13600 KB |
Output is correct |