Submission #1252658

#TimeUsernameProblemLanguageResultExecution timeMemory
1252658pvb.tunglamRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define hash  _hash_
#define y1    _y1_
#define left  _left_
#define right _right_
#define dec   _dec_
#define int   long long
using namespace std;

/*------------- I alone decide my fate! --------------*/
/*  In the hush of the fields, the hub shall arise…   */

int besthub(int R, int /*L*/, const vector<int>& X, long long B) {
    static long long pref[100005];          // tiền tố S
    for (int i = 0; i < R; ++i)
        pref[i] = (i ? pref[i-1] : 0) + X[i];

    auto sum = [&](int l, int r) -> long long {          // Σ X[l..r]
        return pref[r] - (l ? pref[l-1] : 0);
    };

    int ans = 0;
    int l = 0;
    for (int r = 0; r < R; ++r) {
        while (l <= r) {
            int m = (l + r) >> 1;
            long long leftCnt  = m - l;
            long long rightCnt = r - m;
            long long cost =
                  leftCnt  * X[m] - sum(l, m - 1)
                + sum(m + 1, r) - rightCnt * X[m];
            if (cost <= B) break;
            ++l;
        }
        ans = max(ans, r - l + 1);
    }
    return ans;
}

/*---------------------------*/

#ifdef LOCAL
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int R, L; long long B;
    if (!(cin >> R >> L >> B)) return 0;
    vector<int> X(R);
    for (int &x : X) cin >> x;
    cout << besthub(R, L, X, B) << '\n';
}
#endif

/*
  …Across the silent paddies, carts will roll,
  For we have placed the hub where numbers told.
*/

Compilation message (stderr)

/usr/bin/ld: /tmp/ccUm3vHz.o: in function `main':
grader.cpp:(.text.startup+0xaa): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status