#include <bits/stdc++.h>
#define uwu return 0;
using namespace std;
const int SIZE = 2e3 + 5;
int N, Q;
const long long INF = 3e18 + 5;
long long L[SIZE], R[SIZE], W[SIZE], X[SIZE];
int main(){
cin >> N >> Q;
L[N + 1] = INF;
R[0] = -INF;
for (int i = 1; i <= N;i++){
cin >> X[i];
L[i] = X[i];
R[i] = X[i];
W[i] = 0;
}
long long in_W;
for (int i = 1; i <= Q;i++){
cin >> in_W;
if(in_W >= 0){
for (int i = 1; i <= N; i++){
if(X[i] + in_W > R[i]){
if(L[i + 1] > X[i] + in_W){
W[i] += (X[i] + in_W - R[i]);
R[i] = X[i] + in_W;
}
else{
W[i] += (L[i + 1] - R[i]);
R[i] = L[i + 1];
}
}
X[i] += in_W;
}
}
else{
for (int i = 1; i <= N; i++){
if(X[i] + in_W < L[i]){
if(R[i - 1] < X[i] + in_W){
W[i] += (L[i] - (X[i] + in_W));
L[i] = X[i] + in_W;
}
else{
W[i] += (L[i] - R[i - 1]);
L[i] = R[i - 1];
}
}
X[i] += in_W;
}
}
}
for (int i = 1; i <= N;i++){
cout << W[i] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
348 KB |
Output is correct |
5 |
Correct |
9 ms |
348 KB |
Output is correct |
6 |
Correct |
9 ms |
532 KB |
Output is correct |
7 |
Correct |
10 ms |
348 KB |
Output is correct |
8 |
Correct |
9 ms |
348 KB |
Output is correct |
9 |
Correct |
9 ms |
348 KB |
Output is correct |
10 |
Correct |
6 ms |
516 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
9 ms |
348 KB |
Output is correct |
16 |
Correct |
9 ms |
348 KB |
Output is correct |
17 |
Correct |
8 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
348 KB |
Output is correct |
5 |
Correct |
9 ms |
348 KB |
Output is correct |
6 |
Correct |
9 ms |
532 KB |
Output is correct |
7 |
Correct |
10 ms |
348 KB |
Output is correct |
8 |
Correct |
9 ms |
348 KB |
Output is correct |
9 |
Correct |
9 ms |
348 KB |
Output is correct |
10 |
Correct |
6 ms |
516 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
9 ms |
348 KB |
Output is correct |
16 |
Correct |
9 ms |
348 KB |
Output is correct |
17 |
Correct |
8 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
4 ms |
344 KB |
Output is correct |
20 |
Correct |
62 ms |
2328 KB |
Output is correct |
21 |
Correct |
63 ms |
2332 KB |
Output is correct |
22 |
Correct |
104 ms |
2128 KB |
Output is correct |
23 |
Correct |
625 ms |
1872 KB |
Output is correct |
24 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
25 |
Halted |
0 ms |
0 KB |
- |