# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
304588 | hieppgga | 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>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long
using namespace std;
int n,l,k,a[100004],sum[100004],ans;
bool solve(int flag,int res)
{
if(sum[flag+res]-sum[flag]-a[flag]*res+res*a[flag]-(sum[flag-1]-sum[flag-res-1])<=k) return true;
return false;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>l>>k;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
for(int i=1;i<=n;i++)
{
int l=0,r=min(i-1,n-i),mid;
while(l<=r)
{
mid=(l+r)/2;
if(solve(i,mid)) l=mid+1;
else r=mid-1;
}
ans=max(ans,2*r+1);
}
cout<<ans;
}