# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
725442 | Mauve | 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 <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
//using namespace __gnu_pbds;
using namespace std;
//#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define INF 4000000000000000000
#define MOD 1000000007
#define ll long long
#define pb push_back
#define A 900000011
#define ss second
#define endl '\n'
#define ff first
ll n,m,l,r,i,ii,jj,xx,yy,j,t,x,y,z,T,k,p,ans,a[100005];
bool shaa(ll k){
ll med=(k-1)/2,sum=0,ans;
for(ll i=0;i<k;i++) sum+=abs(a[med]-a[i]);
ans=sum;
for(ll i=k;i<n;i++){
sum-=(a[med]-a[i-k]);
sum+=(med-(i-k))*(a[med+1]-a[med]);
sum-=(i-1-med)*(a[med+1]-a[med]);
med++;
sum+=(a[i]-a[med]);
ans=min(ans,sum);
}
if(ans<=p) return true;
else return false;
}
ll besthub(ll R, ll L, ll X[], ll B){
ll l=0,r=R,m;
for(int i=0;i<R;i++) a[i]=X[i];
n=R;
p=B;
while(r-l>1){
m=(r+l)/2;
if(shaa(m)) l=m;
else r=m-1;
}
if(shaa(r)) return r;
else return l;
}