Submission #508831

#TimeUsernameProblemLanguageResultExecution timeMemory
508831tabrRice Hub (IOI11_ricehub)C++17
100 / 100
15 ms1484 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int besthub(int n, int, int* x, long long b) {
    vector<long long> pref(n + 1);
    for (int i = 0; i < n; i++) {
        pref[i + 1] = pref[i] + x[i];
    }
    int lo = 1;
    int hi = n + 1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        int ok = 0;
        for (int i = 0; i + mid <= n; i++) {
            for (int j = max(i, (i + i + mid) / 2 - 1); j <= min(i + mid - 1, (i + i + mid) / 2 + 1); j++) {
                long long c = pref[i + mid] - pref[j] - 1LL * x[j] * (i + mid - j);
                c += 1LL * x[j] * (j - i) - (pref[j] - pref[i]);
                if (c <= b) {
                    ok = 1;
                }
            }
        }
        if (ok) {
            lo = mid;
        } else {
            hi = mid;
        }
    }
    return lo;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...