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 "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll cum[100005],tab[100005];
ll sum(int a,int b){
if(a>b)return 0;
return cum[b]-(a?cum[a-1]:0);
}
ll cost(int i,int j,int x){
ll idx=lower_bound(tab+i,tab+j+1,x)-tab;
ll nb_a=idx-i,nb_b=j-idx+1;
return nb_a*x-sum(i,idx-1)+sum(idx,j)-nb_b*x;
}
int besthub(int R, int L, int X[], long long B)
{
for (int i = 0; i < R; ++i)
{
tab[i]=X[i];
cum[i]=X[i];
if(i)cum[i]+=cum[i-1];
}
int ans=1;
for (int i = 0; i < R; ++i)
{
for (int j = i+1; j < R; ++j)
{
//cerr<<i<<" "<<j<<" "<<i+(j-i)/2<<"\n";
if(cost(i,j,X[i+(j-i)/2])<=B)
ans=max(ans,j-i+1);
/*
ll x=sum(i,j)/(j-i+1);
if(cost(i,j,x)<=B)ans=max(ans,j-i+1);
else{
x=(sum(i,j)+(j-i))/(j-i+1);
if(cost(i,j,x)<=B)ans=max(ans,j-i+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... |