#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e3+5;
int arr[N], mn[N], mx[N], ans[N];
int now = 0;
signed main(){
fastio
int n,q;
cin >> n >> q;
for(int i = 1;i <= n;i++){
cin >> arr[i];
mn[i] = mx[i] = arr[i];
}
for(int i = 0;i < q;i++){
int x;
cin >> x;
for(int j = 1;j <= n;j++){
arr[j] += x;
if(x < 0){
if(j==1){
ans[j] += max((int)0,mn[j]-arr[j]);
}else{
if(mn[j] > mx[j-1]){
ans[j] += max((int)0,mn[j]-max(mx[j-1],arr[j]));
}
}
}else{
if(j==n){
ans[j] += max((int)0,arr[j]-mx[j]);
}else{
if(mx[j] < mn[j+1]){
ans[j] += max((int)0,min(arr[j],mn[j+1])-mx[j]);
}
}
}
mn[j] = min(mn[j],arr[j]);
mx[j] = max(mx[j],arr[j]);
}
}
for(int i = 1;i <= n;i++)
cout << ans[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
15 ms |
424 KB |
Output is correct |
5 |
Correct |
15 ms |
412 KB |
Output is correct |
6 |
Correct |
15 ms |
416 KB |
Output is correct |
7 |
Correct |
14 ms |
336 KB |
Output is correct |
8 |
Correct |
15 ms |
420 KB |
Output is correct |
9 |
Correct |
14 ms |
340 KB |
Output is correct |
10 |
Correct |
14 ms |
340 KB |
Output is correct |
11 |
Correct |
11 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
15 ms |
424 KB |
Output is correct |
16 |
Correct |
16 ms |
328 KB |
Output is correct |
17 |
Correct |
13 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
13 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
15 ms |
424 KB |
Output is correct |
5 |
Correct |
15 ms |
412 KB |
Output is correct |
6 |
Correct |
15 ms |
416 KB |
Output is correct |
7 |
Correct |
14 ms |
336 KB |
Output is correct |
8 |
Correct |
15 ms |
420 KB |
Output is correct |
9 |
Correct |
14 ms |
340 KB |
Output is correct |
10 |
Correct |
14 ms |
340 KB |
Output is correct |
11 |
Correct |
11 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
15 ms |
424 KB |
Output is correct |
16 |
Correct |
16 ms |
328 KB |
Output is correct |
17 |
Correct |
13 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
13 ms |
340 KB |
Output is correct |
20 |
Correct |
28 ms |
2380 KB |
Output is correct |
21 |
Correct |
35 ms |
2252 KB |
Output is correct |
22 |
Correct |
123 ms |
1980 KB |
Output is correct |
23 |
Correct |
1277 ms |
1884 KB |
Output is correct |
24 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
25 |
Halted |
0 ms |
0 KB |
- |