# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568685 | dantoh000 | Snowball (JOI21_ho_t2) | C++14 | 118 ms | 16844 KiB |
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 int long long
using namespace std;
int n,q;
int p[200005];
int D[200005];
int l[200005];
int r[200005];
int pos[200005];
int ans[200005];
main(){
scanf("%lld%lld",&n,&q);
for (int i = 1; i <= n; i++){
scanf("%lld",&p[i]);
}
int cur = 0;
l[0] = r[0] = D[0] = 0;
for (int i = 1, x; i <= q+1; i++){
if (i == q+1) x = 0;
else scanf("%lld",&x);
cur += x;
l[i] = min(l[i-1], cur);
r[i] = max(r[i-1], cur);
D[i] = r[i]-l[i];
pos[i] = cur;
}
ans[1] += -l[q];
ans[n] += r[q];
for (int i = 1; i < n; i++){
int d = p[i+1]-p[i];
int id = lower_bound(D, D+q+1, d) - D;
int L = -l[id];
int R = r[id];
L = min(L, d);
R = min(R, d);
if (pos[id] == l[id]) L = min(L, d - R);
else if (pos[id] == r[id]) R = min(R, d - L);
///printf("position %d moves %d left, position %d moves %d right\n",i+1,L,i,R);
ans[i] += R;
ans[i+1] += L;
}
for (int i = 1; i <= n; i++){
printf("%lld\n",ans[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |