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>
#include "ricehub.h"
using namespace std;
using ll = long long;
const int N = 100010;
ll qsl[N], qsr[N];
int besthub(int n, int L, int pos[], ll budget)
{
for (int i = 1; i <= n; ++i) {
qsl[i] += qsl[i-1] + pos[i-1];
qsr[i] = qsr[i-1] + (L - pos[i-1]);
}
auto check = [&] (int cnt) {
for (int l = 1, r = cnt; r <= n; ++l, ++r) {
int m = (l+r)/2;
ll d = qsr[m]-qsr[l-1] - (L-pos[m-1])*(m-l+1);
d += qsl[r]-qsl[m] - (pos[m-1])*(r-m);
if (d <= budget) return true;
}
return false;
};
int b = 0;
int e = n;
while (b < e) {
int m = (b+e+1)/2;
if (check(m))
b = m;
else
e = m-1;
}
return b;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |