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;
int besthub(int R, int L, int X[], long long B) {
long long T[R + 1];
T[0] = 0;
for (int i = 1; i <= R; i++) {
T[i] = T[i - 1] + X[i - 1];
}
int ans = 1;
for (int s = 0; s < R; s++) {
int lo = s, hi = R - 1;
while (lo <= hi) {
int t = lo + (hi - lo) / 2;
int p = s + (t - s) / 2;
long long cost = (p - s) * X[p] - (T[p] - T[s]) + (T[t + 1] - T[p + 1]) - (t - p) * X[p];
if (cost <= B) {
ans = max(ans, t - s + 1);
lo = t + 1;
} else {
hi = t - 1;
}
}
}
return ans;
}
# | 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... |