# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880437 | andro | 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"
#define int long long
using namespace std;
int besthub(int R, int L, int X[], long long B){
int ans=0;
for(int i=1;i<=R;i++){
//od desno kolko ih ima u [X[i],X[i]+mid]
// od levo [X[i]-mid,X[i]]
int l=0,r=1e15+1,p=-1;
while(l<=r){
int mid=(l+r)/2;
int c=0;
for(int j=1;j<=R;j++){
if(abs(X[i]-X[j])<=mid)c+=abs(X[i]-X[j]);
}
if(c<=B){
l=mid+1;
p=mid;
}
else {
r=mid-1;
}
}
int u=0;
for(int j=1;j<=R;j++){
if(abs(X[i]-X[j])<=p)u++;
}
ans=max(ans,u);
}
return ans;
}/*
signed main(){
int X[4]={0,10,12,14};
cout<<besthub(3,14,X,6);
}*/
/*
1 3
2 3
3 3
3
*/