# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
304588 | 2020-09-21T14:40:56 Z | hieppgga | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#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; }