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 l = 1, r = sz;
int mid = (l + r) / 2;
int sz_l = mid - l, sz_r = r - mid;
long long L = 0, R = 0;
for(int i = l; i < mid; i++) {
L += x[mid] - x[i];
}
for(int i = mid + 1; i <= r; i++) {
R += x[i] - x[mid];
}
if(L + R <= lim) {
return true;
}
while(r < n) {
L -= x[mid] - x[l];
R -= (x[mid + 1] - x[mid]) * sz_r;
l++, r++, mid++;
L += (x[mid] - x[mid - 1]) * sz_l;
R += x[r] - x[mid];
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... |