#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
int n1 = n + 1, q1 = q + 1;
vector<long long> v(n1), mini(q1, 0), maxi(q1, 0), Q(q1);
for(int i = 1; i <= n; i++) cin >> v[i];
long long sum = 0;
for(int i = 1; i <= q; i++){
cin >> Q[i];
sum += Q[i];
/*if(i == 0){
mini[i] = min(0ll, sum);
maxi[i] = max(0ll, sum);
continue;
}*/
mini[i] = min(mini[i - 1], sum);
maxi[i] = max(maxi[i - 1], sum);
}
/*for(int i = 0; i <q; i++) cout << mini[i] << " ";
cout << '\n';
for(int i = 0; i <q; i++) cout << maxi[i] << " ";
cout << '\n';*/
auto bs = [&](int i){
int l = 0, r = q + 1;
while(l + 1 < r){
int mid = (l + r) / 2;
if(v[i + 1] - v[i] >= maxi[mid] - mini[mid]) l = mid;
else r = mid;
}
return l;
};
vector<long long> res(n1);
for(int i = 1; i < n; i++){
int x = bs(i);
//cerr << i << ": " << x <<" " << mini[x] << " " << maxi[x]<< '\n';
res[i] += maxi[x];
res[i + 1] -= mini[x];
long long dif = 0;
if(x != q) dif = v[i + 1] - v[i] - (maxi[x] - mini[x]);
if(dif and Q[x + 1] > 0) res[i] += dif;
if(dif and Q[x + 1] <= 0) res[i + 1] += dif;
//cerr << res[i] << " " << res[i+1] << '\n';
}
res[1] -= mini[q];
res[n] += maxi[q];
for(int a = 1; a <= n; a++) cout << res[a] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
552 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
552 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
18 ms |
7248 KB |
Output is correct |
21 |
Correct |
17 ms |
7064 KB |
Output is correct |
22 |
Correct |
16 ms |
6748 KB |
Output is correct |
23 |
Correct |
16 ms |
6764 KB |
Output is correct |
24 |
Correct |
21 ms |
7260 KB |
Output is correct |
25 |
Correct |
76 ms |
13540 KB |
Output is correct |
26 |
Correct |
76 ms |
13480 KB |
Output is correct |
27 |
Correct |
75 ms |
13140 KB |
Output is correct |
28 |
Correct |
75 ms |
13136 KB |
Output is correct |
29 |
Correct |
73 ms |
12684 KB |
Output is correct |
30 |
Correct |
64 ms |
12116 KB |
Output is correct |
31 |
Correct |
41 ms |
11600 KB |
Output is correct |
32 |
Correct |
38 ms |
11604 KB |
Output is correct |
33 |
Correct |
7 ms |
1624 KB |
Output is correct |
34 |
Correct |
74 ms |
13904 KB |
Output is correct |
35 |
Correct |
76 ms |
13140 KB |
Output is correct |
36 |
Correct |
81 ms |
13392 KB |
Output is correct |
37 |
Correct |
76 ms |
13244 KB |
Output is correct |
38 |
Correct |
74 ms |
13140 KB |
Output is correct |
39 |
Correct |
68 ms |
13276 KB |
Output is correct |
40 |
Correct |
62 ms |
13368 KB |
Output is correct |
41 |
Correct |
19 ms |
7764 KB |
Output is correct |
42 |
Correct |
43 ms |
11632 KB |
Output is correct |
43 |
Correct |
50 ms |
14928 KB |
Output is correct |
44 |
Correct |
18 ms |
7704 KB |
Output is correct |
45 |
Correct |
43 ms |
13236 KB |
Output is correct |
46 |
Correct |
52 ms |
15188 KB |
Output is correct |
47 |
Correct |
52 ms |
15412 KB |
Output is correct |
48 |
Correct |
52 ms |
15416 KB |
Output is correct |