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>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 200'010;
ll mn[N], mx[N], mxmn[N], sm[N];
ll ans[N];
ll x[N];
int n, q;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> q;
Loop (i,0,n)
cin >> x[i];
Loop (i,0,q) {
cin >> sm[i+1];
sm[i+1] += sm[i];
mn[i+1] = min(mn[i], sm[i+1]);
mx[i+1] = max(mx[i], sm[i+1]);
mxmn[i+1] = mx[i+1] - mn[i+1];
}
mxmn[q+1] = 1e18;
ans[0] += -mn[q];
Loop (i,0,n-1) {
int j = lower_bound(mxmn, mxmn+q+2, x[i+1]-x[i]) - mxmn;
if (j > q) {
ans[i] += mx[q];
ans[i+1] += -mn[q];
} else {
--j;
ans[i] += mx[j];
ans[i+1] += -mn[j];
ans[i + (sm[j+1]<sm[j])] += x[i+1]-x[i] - mxmn[j];
}
}
ans[n-1] += mx[q];
Loop (i,0,n)
cout << ans[i] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |