Submission #1263064

#TimeUsernameProblemLanguageResultExecution timeMemory
1263064sohamsen15Rice Hub (IOI11_ricehub)C++20
100 / 100
15 ms2376 KiB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int besthub(int n, int maxCoordinate, int aArr[], ll budget) {
    vector<ll> a(n + 1); for (ll i = 1; i <= n; i++) a[i] = aArr[i - 1];
    vector<ll> p(n + 1); p[0] = 0; for (ll i = 1; i <= n; i++) p[i] = a[i] + p[i - 1];
    int ans = 0;

    for (int l = 1; l <= n; l++) {
        int low = l, high = n;

        function<bool(int)> possible = [&](int r) {
            ll m = l + (r - l) / 2;
            ll cost = a[m] * (2 * m + 1 - l - r) + (p[r] + p[l - 1] - 2 * p[m]);
            return cost <= budget;
        };

        while (low <= high) {
            int mid = (low + high) / 2;
            if (possible(mid)) ans = max(ans, mid - l + 1), low = mid + 1;
            else high = mid - 1;
        }
    }

    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...