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"
using namespace std;
#define ll long long
const int mxN = 1e5 + 1;
ll int a[mxN], ps[mxN];
ll int budget;
int n;
bool test(int tar) {
for (int i = (tar + 1) / 2; i <= n - tar / 2; i++) {
ll int cur = 0;
if (tar % 2 == 1) {
cur += (a[i] * (tar / 2)) - (ps[i - 1] - ps[i - 1 - tar / 2]);
cur += (ps[i + tar / 2] - ps[i]) - (a[i] * (tar / 2));
} else {
cur += (a[i] * (tar / 2)) - (ps[i] - ps[i - tar / 2]);
cur += (ps[i + tar / 2] - ps[i]) - (a[i] * (tar / 2));
}
if (cur <= budget) return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B) {
n = R;
for (int i = 1; i <= n; i++) {
a[i] = X[i - 1];
ps[i] = ps[i - 1] + a[i];
}
budget = B;
int lb = 1, rb = n;
while (lb < rb) {
int mid = (lb + rb + 1) >> 1;
if (test(mid)) lb = mid;
else rb = mid - 1;
}
return lb;
}
# | 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... |