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 ll long long
const int N = 200005;
int n, q; ll a[N], w[N];
ll ld[N], rd[N], d[N], ans[N];
int main(){
// freopen("a.in", "r", stdin);
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q;
for(int i = 1; i<=n; ++i)
cin >> a[i];
a[0] = -1e18; a[n+1] = 1e18;
for(int i = 1; i<=q; ++i)
cin >> w[i];
ll cur_sum = 0;
for(int i = 1; i<=q; ++i){
cur_sum += w[i];
ld[i] = max(ld[i-1], -cur_sum);
rd[i] = max(rd[i-1], cur_sum);
}
for(int i = 0; i<=q; ++i)
d[i] = ld[i]+rd[i];
for(int i = 0; i<=n; ++i){
int id = lower_bound(d, d+q+1, a[i+1]-a[i])-d;
if(id==q+1){
ans[i] += rd[q];
ans[i+1] += ld[q];
continue;
}
if(rd[id]!=rd[id-1])
ans[i+1] += ld[id], ans[i] += a[i+1]-a[i]-ld[id];
else ans[i] += rd[id], ans[i+1] += a[i+1]-a[i]-rd[id];
}
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... |