Submission #1267291

#TimeUsernameProblemLanguageResultExecution timeMemory
1267291BlockOGRice Hub (IOI11_ricehub)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>

// mrrrow meeow :3
// go play vivid/stasis now! it's free on steam

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = [] {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    return 0;
}();

int besthub(int r, int l, int x[], long long b) {

    int res = 0;

    int curr;

    {
        curr = x[r / 2];
        int last = 0;
        int diff = 0;
        int used = 0;
        long long sum = 0;
        fo(i, 0, r) {
            sum += abs(x[i] - curr);
            used++;

            while (last <= i && sum > b) {
                sum -= abs(x[last++] - curr);
                used--;
            }

            res = max(res, used);
        }
    }

    {
        curr = x[(r + 1) / 2];
        int last = 0;
        int diff = 0;
        int used = 0;
        long long sum = 0;
        fo(i, 0, r) {
            sum += abs(x[i] - curr);
            used++;

            while (last <= i && sum > b) {
                sum -= abs(x[last++] - curr);
                used--;
            }

            res = max(res, used);
        }
    }

    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...