Submission #1272405

#TimeUsernameProblemLanguageResultExecution timeMemory
1272405btkhgRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;


int besthub(int R, int L, vector<int> &X, long long B) {
    
    vector<long long> P(R + 1, 0);
    for (int i = 0; i < R; i++) P[i + 1] = P[i] + (long long)X[i];

    auto costWindow = [&](int i, int j) -> long long {
        int m = (i + j) / 2;      
        long long xm = X[m];
        long long left  = xm * (m - i) - (P[m] - P[i]);
        long long right = (P[j + 1] - P[m + 1]) - xm * (j - m);
        return left + right;
    };

    int ans = 0;
    for (int i = 0, j = 0; j < R; j++) {
        while (i <= j && costWindow(i, j) > B) ++i;
        if (i <= j) ans = max(ans, j - i + 1);
    }
    return ans;
}

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

    int R, L;
    long long B;
    cin >> R >> L >> B;
    vector<int> X(R);
    for (int i = 0; i < R; i++) cin >> X[i];

    cout << besthub(R, L, X, B) << "\n";
    return 0;
}

Compilation message (stderr)

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