제출 #259498

#제출 시각아이디문제언어결과실행 시간메모리
259498amiratou쌀 창고 (IOI11_ricehub)C++14
68 / 100
1089 ms896 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...