# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
493529 | Leo121 | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KiB |
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"
typedef long long ll;
int besthub(int R, int L, int X[], long long B)
{
int li = 0, ls = 0, mediana, res = 1, nueva_mediana;
ll inversion = 0LL;
while(ls < R - 1){
ls ++;
mediana = (li + ls) / 2;
inversion += ((ll) X[ls] - (ll) X[mediana]);
if(inversion <= B){
res = max(res, ls - li + 1);
continue;
}
while(inversion > B){
inversion -= ((ll) X[mediana] - (ll) X[li]);
nueva_mediana = (li + ls + 1) / 2;
if(mediana != (li + ls + 1) / 2){
inversion -= ((ll) X[nueva_mediana] - (ll) X[mediana]);
}
li ++;
mediana = nueva_mediana;
}
}
return res;
}