#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
int inf = -1e18;
void solve(){
int n, q;
cin >> n >> q;
vector<array<int,3>> ar;
for(int i = 0; i < n; i ++ ){
int x; cin >> x;
ar.push_back({x,x,x});
}
while(q -- ) {
int w;
cin >> w;
if(w > 0){
ar[n-1][0] += w;
ar[n-1][2] = max(ar[n-1][2], ar[n-1][0]);
for(int i = 0; i + 1 < n; i ++ ) {
ar[i][2] = min(ar[i+1][1], max(ar[i][2], ar[i][0] + w));
ar[i][0] += w;
}
}else{
ar[0][0] += w;
ar[0][1] = min(ar[0][1], ar[0][0]);
for(int i = 1; i < n; i ++ ) {
ar[i][1] = max(ar[i-1][2], min(ar[i][1], ar[i][0] + w));
ar[i][0] += w;
};
}
};
for(int i = 0; i < n; i ++ )cout << ar[i][2] - ar[i][1] << '\n';
};
signed main(){
ios_base::sync_with_stdio();
cin.tie(nullptr); cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt -- ){
solve();
};
};
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |