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>
using namespace std;
#define sz(x) (int)(x.size())
#define pb push_back
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
const int mxN=1e5+5;
ll pref[mxN],suff[mxN],a[mxN],n,l,b,above,below;
bool check(int k){
// cout<<k<<"\n";
k--;
for(int i=1;i<=n;i++){
int sub=k/2;
if(a[i]>l)
return 0;
if(i-sub-1<0 || i+k-sub>n)
continue;
below=pref[i-1]-pref[i-sub-1];
above=suff[i+1]-suff[i+k-sub+1];
if(sub*a[i]-below + above-(k-sub)*a[i] <= b)
return 1;
}
return 0;
}
int besthub(int R, int L, int X[], long long B){
n=R; l=L; b=B;
for(int i=1;i<=n;i++)
a[i]=X[i-1];
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
pref[i]=a[i]+pref[i-1];
for(int i=n;i>=1;i--)
suff[i]=a[i]+suff[i+1];
int l=1; int r=n;
int ans=1;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)){
ans=mid; l=mid+1;
} else{
r=mid-1;
}
}
return ans;
}
# | 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... |