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;
typedef long long ll;
ll BIG = 1234567891234567890;
vector<ll> roll_snowballs(vector<ll> snowballs, vector<ll> wind) {
int n = snowballs.size();
int q = wind.size();
ll le = 0, ri = 0; // Pushes to the right/left
ll curr = 0;
vector<pair<ll, ll>> gaps(n+1);
vector<ll> ans(n);
gaps[0] = {BIG, -1};
gaps[n] = {BIG, n-1};
for(int i = 1; i < n; i++) {
gaps[i] = {snowballs[i] - snowballs[i-1], i-1};
}
sort(gaps.begin(), gaps.end());
int j = 0;
for(int i = 0; i < q; i++) {
curr += wind[i];
if(curr > 0) le = max(le, curr);
if(curr < 0) ri = max(ri, -curr);
while(le + ri >= gaps[j].first) {
ll l = le, r = ri, siz = gaps[j].first;
if(curr > 0) l = siz - r;
if(curr < 0) r = siz - l;
ans[gaps[j].second] += l;
ans[gaps[j].second+1] += r;
j++;
}
}
for(; j < n-1; j++) {
ans[gaps[j].second] += le;
ans[gaps[j].second+1] += ri;
}
ans[0] += ri;
ans[n-1] += le;
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<ll> snowballs(n), wind(q);
for(int i = 0; i < n; i++) cin >> snowballs[i];
for(int i = 0; i < q; i++) cin >> wind[i];
vector<ll> ans = roll_snowballs(snowballs, wind);
for(ll a : ans) cout << a << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |