#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define double long double
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int32_t main(){
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, q;
cin>>n>>q;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin>>a[i];
}
vector<int> df(n-1);
for(int i = 1; i < n; i++){
df[i-1] = a[i] - a[i-1];
}
vector<int> mx(q+1, 0), mn(q+1, 0), vals(q+1);
vector<int> que(q);
int sum = 0;
for(int i = 0; i < q; i++){
cin>>que[i];
sum += que[i];
mx[i+1] = max(mx[i], sum);
mn[i+1] = min(mn[i], sum);
vals[i+1] = mx[i+1] - mn[i+1];
}
vector<int> ans(n);
for(int i = 0; i < n-1; i++){
if(vals[q] <= df[i]){
ans[i] += mx[q];
ans[i+1] += (-mn[q]);
continue;
}
int l = 0, r = q;
while(l < r){
int m = (l + r)/2;
if(vals[m] <= df[i]) l = m + 1;
else r = m;
}
l--; // first index <=
ans[i] += mx[l];
ans[i+1] += (-mn[l]);
if(que[l] < 0){
ans[i+1] += (df[i] - vals[l]);
}
else{
ans[i] += (df[i] - vals[l]);
}
}
ans[0] += (-mn[q]);
ans[n-1] += mx[q];
for(int i = 0; i < n; i++){
cout<<ans[i]<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
484 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
484 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
16 ms |
8796 KB |
Output is correct |
21 |
Correct |
14 ms |
8532 KB |
Output is correct |
22 |
Correct |
15 ms |
8284 KB |
Output is correct |
23 |
Correct |
15 ms |
8352 KB |
Output is correct |
24 |
Correct |
34 ms |
8796 KB |
Output is correct |
25 |
Correct |
227 ms |
16700 KB |
Output is correct |
26 |
Correct |
238 ms |
16620 KB |
Output is correct |
27 |
Correct |
236 ms |
16216 KB |
Output is correct |
28 |
Correct |
217 ms |
16468 KB |
Output is correct |
29 |
Correct |
218 ms |
16000 KB |
Output is correct |
30 |
Correct |
205 ms |
15188 KB |
Output is correct |
31 |
Correct |
190 ms |
14644 KB |
Output is correct |
32 |
Correct |
183 ms |
14932 KB |
Output is correct |
33 |
Correct |
21 ms |
2152 KB |
Output is correct |
34 |
Correct |
219 ms |
16980 KB |
Output is correct |
35 |
Correct |
214 ms |
16444 KB |
Output is correct |
36 |
Correct |
214 ms |
16724 KB |
Output is correct |
37 |
Correct |
223 ms |
16468 KB |
Output is correct |
38 |
Correct |
213 ms |
16212 KB |
Output is correct |
39 |
Correct |
235 ms |
16460 KB |
Output is correct |
40 |
Correct |
195 ms |
16308 KB |
Output is correct |
41 |
Correct |
16 ms |
9308 KB |
Output is correct |
42 |
Correct |
182 ms |
14932 KB |
Output is correct |
43 |
Correct |
199 ms |
18120 KB |
Output is correct |
44 |
Correct |
16 ms |
9308 KB |
Output is correct |
45 |
Correct |
204 ms |
16304 KB |
Output is correct |
46 |
Correct |
208 ms |
18320 KB |
Output is correct |
47 |
Correct |
202 ms |
18516 KB |
Output is correct |
48 |
Correct |
198 ms |
18516 KB |
Output is correct |