이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |