| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 338634 | blue | Rice Hub (IOI11_ricehub) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include "ricehub.h"
#include <vector>
using namespace std;
int besthub(int R, int L, int X[], long long B) //fields, max coordinate, i'th field, budget
{
vector<long long> F(R+2);
F[0] = -(2e16 + 1);
F[R+1] = (4e16 + 1);
for(int i = 1; i <= R; i++) F[i] = X[i-1];
int l = 1; //leftmost field
int m = 1; //hub
int r = 1; //rightmost field
long long c = 0; //current cost
int res = 1; //running result
while(1)
{
if(2*m < (l+r))
{
c += (F[m+1] - F[m]) * ((m - (l - 1)) - (r - m));
m++;
}
if(F[r+1] - F[m] + c <= B)
{
c += F[r+1] - F[m];
r++;
}
else
{
c -= (F[m] - F[l]);
l++;
}
res = max(res, r - l + 1);
if(m == R) break;
}
return res;
}
int main()
{
int R, L;
long long B;
cin >> R >> L >> B;
int X[R];
for(int i = 0; i < R; i++) cin >> X[i];
cout << besthub(R, L, X, B) << '\n';
}
