제출 #1104385

#제출 시각아이디문제언어결과실행 시간메모리
1104385M_W_13쌀 창고 (IOI11_ricehub)C++17
100 / 100
16 ms3464 KiB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)

int besthub(int R, int L, int X[], ll B)
{
    ll n = R;
    ll T[n];
    rep(i, n) {
        T[i] = X[i];
    }
    ll p = 0;
    ll k = n + 1;
    ll ans = k;
    while (p < k) {
        ll sr = (p + k)/2;
        int i1 = 0;
        int i2 = sr/2;
        ll ilelewa = i2 + 1;
        ll ileprawa = sr - ilelewa;
        ll S = 0;
        bool czy = false;
        rep(i, sr) {
            S += (abs(T[i] - T[i2]));
        }
        if (S <= B) {
            czy = true;
        }
        i1++;
        while (i1 + sr - 1 < n) {
            S -= abs(T[i1 - 1] - T[i2]);
            S += abs(T[i1 + sr - 1] - T[i2]);
            ilelewa--;
            ileprawa++;
            ll poz = T[i2];
            i2++;
            S += (ilelewa * (T[i2] - poz));
            S -= (ileprawa * (T[i2] - poz));
            ilelewa++;
            ileprawa--;
            if (S <= B) {
                czy = true;
            }
            i1++;
        }
        if (czy) {
            ans = sr;
            p = sr + 1;
        }
        else {
            k = sr;
        }
    }   
    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...