# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28915 | Nikefor | Rice Hub (IOI11_ricehub) | C++98 | 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 "ricehub.h"
int field[10001];
int besthub(int R, int L, int X[], long long B)
{
int optimalGain=0;
int m, l, r;
l = r = m = 0;
long long spent = 0;
int localGain = 0;
while(r<R) {
if(r!=(R-1))r++;
m = ((r-l)%2)?(r+l+1)/2:(r+l)/2;
spent+= X[r]-[m];
if(spent>B) {
optimalGain = max(optimalGain, localGain);
while(spent>B) {
l++;
spent-= X[l]-X[m];
m = ((r-l)%2)?(r+l+1)/2:(r+l)/2;
localGain--;
}
continue;
}
localGain++;
}
return optimalGain ;
}