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"
#define DEBUG 0
using namespace std;
const int N = 1e5 + 10;
int n;
long long lim;
long long x[N];
bool check(int sz) {
int mid = (sz + 1) / 2;
long long L = 0, R = 0;
for(int i = 1; i < mid; i++) {
L += x[mid] - x[i];
}
for(int i = mid + 1; i <= sz; i++) {
R += x[i] - x[mid];
}
if(L + R <= lim) {
return true;
}
int l = 2, r = sz + 1;
for(int m = mid + 1; r <= n; m++, l++, r++) {
L -= x[m - 1] - x[l - 1];
L += x[m] - x[m - 1];
R -= x[m] - x[m - 1];
R += x[r] - x[m];
if(L + R <= lim) {
return true;
}
}
return false;
}
int besthub(int R, int L, int X[], long long B) {
n = R;
lim = B;
for(int i = 1; i <= R; i++) {
x[i] = X[i - 1];
}
int l = 1, r = R, pos = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(check(mid) == true) {
pos = mid;
l = mid + 1;
}
else {
r = mid - 1;
}
}
return pos;
}
# | 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... |