# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
317135 | nandonathaniel | Rice Hub (IOI11_ricehub) | C++14 | 19 ms | 1792 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"
#include "bits/stdc++.h"
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int ki=1,ka=R,res;
while(ki<=ka){
int mid=(ki+ka)/2;
long long cost=0;
int idx=(mid-1)/2;
for(int i=0;i<mid;i++)cost+=abs(X[i]-X[idx]);
long long mini=cost;
for(int i=mid;i<R;i++){
cost-=abs(X[i-mid]-X[idx]);
idx++;
int selisih=X[idx]-X[idx-1];
cost-=(1LL*(i-idx)*selisih);
cost+=(1LL*(mid-1-i+idx)*selisih);
cost+=abs(X[i]-X[idx]);
mini=min(mini,cost);
}
if(mini<=B){
res=mid;
ki=mid+1;
}
else ka=mid-1;
}
return res;
}
Compilation message (stderr)
# | 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... |