# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
346313 | Mefarnis | 쌀 창고 (IOI11_ricehub) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include "ricehub.h"
using namespace std;
long long getCost(int l , int r , int x[], long long sum[]) {
int m = (l+r) >> 1;
long long cost = 0;
if(l < m)
cost += (m-l) * (long long) x[m-1] - (sum[m-1] - sum[l-1]);
if(m < r)
cost += (sum[r] - sum[m]) - (r-m) * (long long) x[m-1];
return cost;
}
int besthub(int n, int xmax, int x[], long long budget)
{
int ans = 0;
long long sum[n+1];
sum[0] = 0;
for( int i = 1 ; i <= n ; i++ )
sum[i] = sum[i-1] + x[i-1];
for( int l = 1 , r = 1 ; l <= n ; l++ ) {
r = max(l,r);
while(r < n && getCost(l,r+1,x,sum) <= budget)
r++;
ans = max(ans,r-l+1);
}
return ans;
}
int main() {
int n = 5;
int xmax = 20;
int x[5];
x[0] = 1;
x[1] = 2;
x[2] = 10;
x[3] = 12;
x[4] = 14;
long long b = 6;
int ans = besthub(n,xmax,x,b);
printf("%d\n",ans);
return 0;
}