Submission #897235

#TimeUsernameProblemLanguageResultExecution timeMemory
897235arbuzickSnowball (JOI21_ho_t2)C++17
100 / 100
89 ms17116 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n, q; cin >> n >> q; vector<long long> x(n); for (int i = 0; i < n; ++i) { cin >> x[i]; } vector<long long> w(q), pr(q + 1), pr_mn(q + 1), pr_mx(q + 1); for (int i = 0; i < q; ++i) { cin >> w[i]; pr[i + 1] = pr[i] + w[i]; pr_mn[i + 1] = min(pr_mn[i], pr[i + 1]); pr_mx[i + 1] = max(pr_mx[i], pr[i + 1]); } vector<long long> ans(n); for (int i = 0; i < n - 1; ++i) { int l = 0, r = q + 1; while (l < r - 1) { int m = (l + r) / 2; if (pr_mx[m] - pr_mn[m] >= x[i + 1] - x[i]) { r = m; } else { l = m; } } if (r == q + 1) { ans[i] += pr_mx[q]; ans[i + 1] -= pr_mn[q]; } else if (pr[r] > pr[l]) { ans[i + 1] -= pr_mn[r]; ans[i] += x[i + 1] - x[i] + pr_mn[r]; } else { ans[i] += pr_mx[r]; ans[i + 1] += x[i + 1] - x[i] - pr_mx[r]; } } ans[0] -= pr_mn[q]; ans[n - 1] += pr_mx[q]; for (int i = 0; i < n; ++i) { cout << ans[i] << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...