//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
#define PB push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define CASE int t;cin>>t;for(int ca=1;ca<=t;ca++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
const int MAX = 1 << 20, MOD = 1e9 + 7;
ll a[MAX], ans[MAX];
pll rng[MAX];
void solve(){
int n, q;
cin >> n >> q;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
ll mx = 0, mn = 0, now = 0;
for(int i = 1;i <= q;i++){
ll x;
cin >> x;
now += x;
mx = max(mx, now);
mn = min(mn, now);
rng[i] = {mn, mx};
}
ans[1] = -rng[q].F;
ans[n] = rng[q].S;
for(int i = 1;i < n;i++){
ll l = 0, r = q + 1;
while(l < r){
int mid = (r - l) / 2 + l;
if(a[i] + rng[mid].S <= a[i + 1] + rng[mid].F)
l = mid + 1;
else
r = mid;
}
l--;
// cout << i << " " << l << '\n';
ans[i] += rng[l].S;
ans[i + 1] += -rng[l].F;
if(l == q)
continue;
if(rng[l + 1].S > rng[l].S)
ans[i] += (rng[l + 1].F + a[i + 1]) - (rng[l].S + a[i]);
else
ans[i + 1] += (a[i + 1] + rng[l].F) - (a[i] + rng[l].S);
}
for(int i = 1;i <= n;i++)
cout << ans[i] << '\n';
}
int main(){
IOS
// CASE
solve();
return 0;
}
/*
10 10
-56 -43 -39 -31 -22 -5 0 12 18 22
-3
0
5
-4
-2
10
-13
-1
9
6
1 -3 0
2 -3 0
3 -3 2
4 -3 2
5 -4 2
6 -4 6
7 -7 6
8 -8 6
9 -8 6
10 -8 7
1 7
2 2
3 5
4 5
5 9
6 4
7 6
8 5
9 2
14
8
7
9
13
10
9
8
5
10
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
380 KB |
Output is correct |
6 |
Correct |
1 ms |
376 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
380 KB |
Output is correct |
6 |
Correct |
1 ms |
376 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
24 ms |
5552 KB |
Output is correct |
21 |
Correct |
24 ms |
5312 KB |
Output is correct |
22 |
Correct |
23 ms |
5144 KB |
Output is correct |
23 |
Correct |
21 ms |
5080 KB |
Output is correct |
24 |
Correct |
27 ms |
5452 KB |
Output is correct |
25 |
Correct |
88 ms |
11988 KB |
Output is correct |
26 |
Correct |
87 ms |
11724 KB |
Output is correct |
27 |
Correct |
86 ms |
11476 KB |
Output is correct |
28 |
Correct |
89 ms |
11624 KB |
Output is correct |
29 |
Correct |
86 ms |
11100 KB |
Output is correct |
30 |
Correct |
79 ms |
10500 KB |
Output is correct |
31 |
Correct |
58 ms |
9976 KB |
Output is correct |
32 |
Correct |
54 ms |
10116 KB |
Output is correct |
33 |
Correct |
9 ms |
1488 KB |
Output is correct |
34 |
Correct |
91 ms |
12236 KB |
Output is correct |
35 |
Correct |
93 ms |
11668 KB |
Output is correct |
36 |
Correct |
93 ms |
11876 KB |
Output is correct |
37 |
Correct |
85 ms |
11564 KB |
Output is correct |
38 |
Correct |
86 ms |
11480 KB |
Output is correct |
39 |
Correct |
86 ms |
11588 KB |
Output is correct |
40 |
Correct |
67 ms |
11652 KB |
Output is correct |
41 |
Correct |
26 ms |
6096 KB |
Output is correct |
42 |
Correct |
55 ms |
10016 KB |
Output is correct |
43 |
Correct |
73 ms |
13460 KB |
Output is correct |
44 |
Correct |
33 ms |
6060 KB |
Output is correct |
45 |
Correct |
64 ms |
11552 KB |
Output is correct |
46 |
Correct |
74 ms |
13512 KB |
Output is correct |
47 |
Correct |
79 ms |
13680 KB |
Output is correct |
48 |
Correct |
78 ms |
13728 KB |
Output is correct |