#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5;
pair<ll,ll> lr[N];
ll v[N];
ll n,k,cnt = 0;
ll get(ll nr){
ll l = 0,r = cnt - 1;
while(l != r){
ll mij = (l + r + 1)/2;
if(lr[mij].second - lr[mij].first <= nr){
l = mij;
}else{
r = mij - 1;
}
}
return l;
}
int main(){
cin>>n>>k;
for(ll i = 0;i < n;i++){
cin>>v[i];
}
ll cur = 0,l = 0,r = 0;
lr[cnt++] = {0,0};
for(ll i = 0;i < k;i++){
ll x;
cin>>x;
cur+=x;
r = max(r,cur);
l = min(l,cur);
if(lr[cnt - 1] == pair<ll,ll>{l,r})continue;
lr[cnt++] = {l,r};
}
for(ll i = 0;i < n;i++){
ll ans = 0;
///add back
if(i == 0)ans+=abs(l);
else{
ll length = v[i] - v[i - 1];
ll id = get(length);
if(id == cnt - 1 || lr[id].first == lr[id + 1].first){
ans+=-lr[id].first;
}else{
ans+=length - lr[id].second;
}
}
if(i == n - 1)ans+=abs(r);
else{
ll length = v[i + 1] - v[i];
ll id = get(length);
if(id == cnt - 1 || lr[id].second == lr[id + 1].second){
ans+=lr[id].second;
}else{
ans+=length + lr[id].first;
}
}
cout<<ans<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2516 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2532 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2516 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2532 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
59 ms |
6996 KB |
Output is correct |
21 |
Correct |
57 ms |
6684 KB |
Output is correct |
22 |
Correct |
47 ms |
6480 KB |
Output is correct |
23 |
Correct |
45 ms |
6480 KB |
Output is correct |
24 |
Correct |
51 ms |
6736 KB |
Output is correct |
25 |
Correct |
164 ms |
10320 KB |
Output is correct |
26 |
Correct |
182 ms |
10196 KB |
Output is correct |
27 |
Correct |
191 ms |
9688 KB |
Output is correct |
28 |
Correct |
158 ms |
9552 KB |
Output is correct |
29 |
Correct |
146 ms |
9040 KB |
Output is correct |
30 |
Correct |
117 ms |
6476 KB |
Output is correct |
31 |
Correct |
92 ms |
5964 KB |
Output is correct |
32 |
Correct |
100 ms |
5972 KB |
Output is correct |
33 |
Correct |
21 ms |
3164 KB |
Output is correct |
34 |
Correct |
145 ms |
8144 KB |
Output is correct |
35 |
Correct |
170 ms |
7504 KB |
Output is correct |
36 |
Correct |
164 ms |
10240 KB |
Output is correct |
37 |
Correct |
157 ms |
9688 KB |
Output is correct |
38 |
Correct |
157 ms |
9688 KB |
Output is correct |
39 |
Correct |
146 ms |
9812 KB |
Output is correct |
40 |
Correct |
119 ms |
9808 KB |
Output is correct |
41 |
Correct |
64 ms |
7576 KB |
Output is correct |
42 |
Correct |
92 ms |
5972 KB |
Output is correct |
43 |
Correct |
146 ms |
11732 KB |
Output is correct |
44 |
Correct |
63 ms |
7328 KB |
Output is correct |
45 |
Correct |
117 ms |
9812 KB |
Output is correct |
46 |
Correct |
210 ms |
11856 KB |
Output is correct |
47 |
Correct |
155 ms |
11860 KB |
Output is correct |
48 |
Correct |
158 ms |
12240 KB |
Output is correct |