# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1003252 | vjudge1 | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "ricehub.h"
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pb push_back
#define p_b pop_back
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
ll n = R, i, j, ans = 0;
ll h[n+5], pref[n+5];
ll l = 1, r = L;
vl v;
v.pb(0);
pref[0] = 0;
for(i = 1; i <= n; i++)
{
h[i] = X[i-1];
pref[i] = pref[i-1] + h[i];
v.pb(X[i-1]);
}
L = min(L, h[n]);
for(ll mid = 0; mid <= L; mid++)
{
ll lb = lower_bound(all(v), mid) - v.begin();
ll tl = lb - 1, tr = lb + 1, sum1 = 0, sum2 = 0;
//cout << "mid: " << mid << " lb: " << lb << " sum1: ";
while((tl >= 1 && tl <= n) || (tr >= 1 && tr <= n))
{
ll cost1 = LLONG_MAX, cost2 = LLONG_MAX;
if(tl >= 1 && tl <= n)
cost1 = mid - h[tl];
if(tr >= 1 && tr <= n)
cost2 = h[tr] - mid;
//cout << "cost1: " << cost1 << " cost2: " << cost2 << "\n";
if(cost1 == LLONG_MAX && cost2 == LLONG_MAX)
break;
if(cost1 <= cost2){
sum1 += cost1;
tl--;
}
else{
sum2 += cost2;
tr++;
}
if(sum1 + sum2 > B)
{
if(cost1 <= cost2){
sum1 -= cost1;
tl++;
}
else{
sum2 -= cost2;
tr--;
}
break;
}
}
//cout << sum1 << " sum2: " << sum2 << "\n";
tl++, tr--;
ans = max(ans, (tr - tl + 1));
}
return ans;
}