# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284509 | Basilhijaz | Rice Hub (IOI11_ricehub) | C++17 | 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"
using namespace std;
typedef long long ll;
int besthub(int R, int L, ll X[], long long B)
{
ll pre[R + 1];
pre[0] = 0;
for(int i = 0; i < R; i++){
pre[i + 1] = X[i] + pre[i];
}
int lo = 0; int hi = R;
while(lo < hi){
ll mid = (lo + hi + 1)/2;
bool can = 0;
for(int i = 0; i + mid - 1 < R; i++){
ll sum = 0;
ll nos = (i + i + mid - 1)/2;
sum += X[nos]*mid - (pre[nos] - pre[i]);
sum += (pre[i + i + mid - 1] - pre[nos]) - X[nos]*mid;
if(sum <= B){
can = 1;
break;
}
}
if(can){
lo = mid;
}
else{
hi = mid - 1;
}
}
return lo;
}