Submission #1252662

#TimeUsernameProblemLanguageResultExecution timeMemory
1252662pvb.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! --------------*/
/*   Across the silent paddies, carts will roll…      */

const int MAXR = 100000 + 5;
int R, L;
long long B;
int X[MAXR];
long long pref[MAXR];

int besthub() {
    // Tính mảng tiền tố pref[i] = X[0] + … + X[i]
    for (int i = 0; i < R; ++i) {
        pref[i] = X[i] + (i ? pref[i-1] : 0);
    }

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

    int ans = 0, l = 0;
    // Mỗi r duyệt từ 0..R-1, đẩy l cho tới khi cost(l,r) ≤ B
    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;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> R >> L >> B;
    for (int i = 0; i < R; ++i) {
        cin >> X[i];
    }

    cout << besthub() << "\n";
    return 0;
}

/*
  …For we have placed the hub where numbers told.
*/

Compilation message (stderr)

/usr/bin/ld: /tmp/cccXO04P.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccPJhaZr.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cccXO04P.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