Submission #730521

#TimeUsernameProblemLanguageResultExecution timeMemory
730521t6twotwoRice Hub (IOI11_ricehub)C++17
100 / 100
19 ms2516 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int N, int L, int X[], long long B) {
    vector<int64_t> pfs(N + 1);
    for (int i = 0; i < N; i++) {
        pfs[i + 1] = pfs[i] + X[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int lo = i, hi = N - 1;
        while (lo < hi) {
            int x = (lo + hi + 1) / 2;
            int p = (i + x) / 2;
            if ((pfs[x + 1] - pfs[p + 1]) - (pfs[p + 1] - pfs[i]) + 1LL * X[p] * ((p + 1 - i) - (x - p)) <= B) {
                lo = x;
            } else {
                hi = x - 1;
            }
        }
        ans = max(ans, lo + 1 - i);
    }
    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...