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
int cum[100005];
int sum(int a,int b){
if(a>b)return 0;
return cum[b]-(a?cum[a-1]:0);
}
int besthub(int R, int L, int X[], long long B)
{
for (int i = 0; i < R; ++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)
{
ll x=sum(i,j)/(j-i+1);
ll idx=lower_bound(X+i,X+j,x)-X;
ll nb_a=idx-i,nb_b=j-idx+1;
ll cost=nb_a*x-sum(i,idx-1)+sum(idx,j)-nb_b*x;
if(cost<=B)ans=max(ans,j-i+1);
else{
x=(sum(i,j)+(j-i))/(j-i+1);
idx=lower_bound(X+i,X+j,x)-X;
nb_a=idx-i,nb_b=j-idx+1;
cost=nb_a*x-sum(i,idx-1)+sum(idx,j)-nb_b*x;
if(cost<=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... |