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;
int besthub(int R, int L, int X[], long long B) {
vector<long long> pref(R + 1);
for (int i = 0; i < R; ++i) {
pref[i + 1] = pref[i] + X[i];
}
auto check = [&](int len) {
for (int l = 0, r = len; r <= R; ++l, ++r) {
int m = (l + r) >> 1;
if ((long long) (m - l) * X[m] - (pref[m] - pref[l]) + (pref[r] - pref[m]) - (long long) (r - m) * X[m] <= B) {
return true;
}
}
return false;
};
int l = 0, r = R;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (check(mid)) {
l = mid;
} else {
r = mid - 1;
}
}
return l;
}
# | 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... |