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 "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int besthub (int R, int L, int X[], long long B) {
vector<int> x(R + 5);
vector<ll> pref(R + 5);
for (int i = 1; i <= R; i++) x[i] = X[i - 1], pref[i] = pref[i - 1] + x[i];
auto ck = [&] (int val) {
for (int l = 1, r = l + val - 1; r <= R; l++, r++) {
int mid = (l + r) >> 1;
ll curl = x[mid] * (mid - l) - (pref[mid - 1] - pref[l - 1]);
ll curr = (pref[r] - pref[mid]) - x[mid] * (r - mid);
if (curl + curr <= B) return 1;
}
return 0;
};
int l = 1, r = R;
while (l <= r) {
int mid = (l + r) >> 1;
if (ck(mid)) l = mid + 1;
else r = mid - 1;
}
return r;
}
# | 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... |