Submission #621500

#TimeUsernameProblemLanguageResultExecution timeMemory
621500elkernosSnowball (JOI21_ho_t2)C++17
100 / 100
99 ms13740 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define x first #define y second int32_t main() { cin.tie(0)->sync_with_stdio(0); int n, q; cin >> n >> q; vector<int> a(n + 1); vector<pair<int, int>> ord; for(int i = 1; i <= n; i++) { cin >> a[i]; if(i > 1) { ord.emplace_back(a[i] - a[i - 1], i); } } sort(ord.begin(), ord.end()); int sum = 0, l = 0, r = 0; int p = 0; vector<int> ans(n + 1); while(q--) { int w; cin >> w; sum += w; if(r < sum) { r = sum; while(p < n - 1 && ord[p].x < -l + r) { ans[ord[p].y] += (-l); ans[ord[p].y - 1] += ord[p].x - (-l); p++; } } if(l > sum) { l = sum; while(p < n - 1 && ord[p].x < -l + r) { ans[ord[p].y - 1] += r; ans[ord[p].y] += ord[p].x - r; p++; } } } ans[1] += (-l); ans[n] += r; for(int i = p; i < (int)ord.size(); i++) { ans[ord[i].y - 1] += r; ans[ord[i].y] += (-l); } for(int i = 1; i <= n; i++) { cout << ans[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...