This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 500
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1000000007;//998244353;
const ll inf=1e18*4;
const ld pai=acos(-1);
#include "ricehub.h"
ll n,k;
ll a[100009],sum[100009];
ll check2(ll l,ll r){
ll x=a[mid];
ll num1=mid-l;
ll num2=r-mid;
ll sum1=0;
if(mid)sum1+=sum[mid-1];
if(l)sum1-=sum[l-1];
ll sum2=sum[r]-sum[mid];
ll all=((num1*x)-sum1)+(sum2-(num2*x));
return (all<=k);
}
ll check1(ll x){
ll L=0,R=x-1;
if(check2(L,R))return 1;
for(ll i=x;i<n;i++){
L++,R++;
if(check2(L,R))return 1;
}
return 0;
}
int besthub(int R, int L, int X[], long long B){
n=R,k=B;
for(ll i=0;i<n;i++)a[i]=X[i];
sort(a,a+n);
for(ll i=0;i<n;i++){
sum[i]=a[i];
if(i)sum[i]+=sum[i-1];
}
ll l=1,r=n+1;
while(r-l>1){
if(check1(mid))l=mid;
else r=mid;
}
return l;
}
# | 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... |