#include "ricehub.h"
#include <vector>
#include <algorithm>
using namespace std;
int besthub(int R, int L, int X[], long long B) {
vector<long long> a(R + 1), p(R + 1);
for (int i = 1; i <= R; ++i) a[i] = X[i - 1];
for (int i = 1; i <= R; ++i) p[i] = p[i - 1] + a[i];
long long res = 0;
for (int i = 1; i <= R; ++i) {
int l = 0, r = R;
while (l <= r) {
int m = (l + r) / 2;
int x = m / 2;
int y = m - x;
if (i > (R + 1) / 2) swap(x, y);
if (i - x - 1 < 0 || i + y > R) {
r = m - 1;
continue;
}
long long cost = x * a[i] - (p[i - 1] - p[i - x - 1]) + (p[i + y] - p[i]) - y * a[i];
if (cost <= B) {
res = max(res, (long long)(x + y + 1));
l = m + 1;
} else {
r = m - 1;
}
}
}
return res;
}
# | 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... |