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>
#include "ricehub.h"
using namespace std;
bool check(int x[], int n, int siz, long long b){
int med = n/2;
long long f = 0;
long long s = 0;
for(int i = 0;i<=med;i++){
f+=x[med]-x[i];
}
for(int i = med+1;i<n;i++){
s+=x[i]-x[med];
}
if(f+s<=b)
return 1;
for(int i = 1;i<=siz-n;i++){
f+=1LL*(x[med+i]-x[med+i-1])*(med+1);
f-=(x[med+i]-x[i-1]);
s-=1LL*(x[med+i]-x[med+i-1])*(n-med-1);
s+=(x[n+i-1]-x[med+i]);
if(f+s<=b){
return 1;
}
}
return 0;
}
int besthub(int n, int l, int x[], long long b)
{
int lo = 0;
int hi = n;
while(lo<hi){
int mid = (lo+hi+1)/2;
if(check(x,mid,n,b)){
lo=mid;
}
else{
hi=mid-1;
}
}
return lo;
}
# | 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... |