Submission #1199433

#TimeUsernameProblemLanguageResultExecution timeMemory
1199433AMel0nRice Hub (IOI11_ricehub)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first 
#define S second

#include "ricehub.h"

ll N;
vector<ll> ps;
vector<ll> V;

ll cost(ll l, ll r) {
    ll m = (l + r) / 2;
    // sum of the distance between all the coords from rice fields [l, r] to m
    return ps[r+1] - ps[m] - V[m] * (r-m)    +   V[m] * (m-l+1) - ps[m] - ps[l] ;
}

int besthub(int R, int L, int X[], ll B) {
    ::N = R;
    ps.resize(N+1);
    V.resize(N);
    FOR(i,N) {ps[i+1] = ps[i] + X[i]; V[i] = X[i];}

    ll res = 0, l = 0;
    FOR(r,N) { // indices of the ricehubs
        ll c = cost(l, r);
        while(c > B) {
            l++;
            c = cost(l, r);
        }
        res = max(res, r - l + 1);
    }
    return res;
}

// signed main() {
//     cin.tie(0); ios::sync_with_stdio(false);
    
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...