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 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |