제출 #679096

#제출 시각아이디문제언어결과실행 시간메모리
679096jiahng쌀 창고 (IOI11_ricehub)C++14
100 / 100
14 ms3276 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;


int R,L;
ll B;
long long ss[maxn],X[maxn];
bool pos(int x){
    FOR(i,1,R+1-x){
        // [i, i+x-1]
        int med = i+(x-1)/2;
        ll cost = X[med] * (med-i+1) - (ss[med] - ss[i-1]);
        cost += (ss[i+x-1] - ss[med]) - X[med]*(i+x-1-med);
        if (cost <= B) return 1;
    }
    return 0;
}
int besthub(int R, int L, int X[], long long B){
    ::R = R; ::L = L; ::B = B;
    FOR(i,1,R) ss[i] = ss[i-1] + X[i-1];
    FOR(i,1,R) ::X[i] = X[i-1];
    int l = 1, r = R+1;
    while (l + 1 < r){
        int m = (l + r) / 2;
        if (pos(m)) l = m;
        else r = m;
    }
    return l;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...