제출 #393150

#제출 시각아이디문제언어결과실행 시간메모리
393150MarcoMeijerRice Hub (IOI11_ricehub)C++14
100 / 100
22 ms2928 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int besthub(int R, int L, int X[], ll B) {
    int lb=0, ub=0;
    ll cost = 0;
    vll sm; sm.push_back(0);
    RE(i,R) sm.push_back(sm.back() + X[i]);
    auto updateCost = [&]() {
        int mid = (lb+ub)/2;
        cost = 0;
        // [lb,mid]
        cost += (mid-lb+1)*X[mid];
        cost -= sm[mid+1]-sm[lb];
        
        // [mid,ub]
        cost -= (ub-mid+1)*X[mid];
        cost += sm[ub+1]-sm[mid];
    };
    int ans = 0;
    while(lb < R) {
        while(ub < R-1 && cost <= B) {
            ub++;
            updateCost();
        }
        if(cost > B) {
            ub--;
            updateCost();
        }
        ans = max(ans, ub-lb+1);
        lb++;
    }
    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...