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>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 2e5 + 5;
ll n, q, X[NMAX], W[NMAX], mn[NMAX], mx[NMAX], cur, v[NMAX], ans[NMAX];
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> X[i];
for(int i = 1; i <= q; i++) {
cin >> W[i];
cur += W[i];
mn[i] = min(mn[i - 1], cur);
mx[i] = max(mx[i - 1], cur);
v[i] = mx[i] - mn[i];
}
ans[1] += -mn[q];
ans[n] += mx[q];
for(int i = 1; i < n; i++){
int j = lower_bound(v, v + q + 1, X[i + 1] - X[i]) - v - 1;
ans[i] += mx[j];
ans[i + 1] += -mn[j];
if(j < n) {
ll t = X[i + 1] - X[i] - mx[j] + mn[j];
ans[i + (W[j + 1] < 0)] += t;
}
}
for(int i = 1; i <= n; i++) cout << ans[i] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |