Submission #504015

#TimeUsernameProblemLanguageResultExecution timeMemory
504015couplefireSnowball (JOI21_ho_t2)C++17
100 / 100
95 ms16880 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...