This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |