Submission #898739

# Submission time Handle Problem Language Result Execution time Memory
898739 2024-01-05T05:16:07 Z Samot19 Rice Hub (IOI11_ricehub) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <cmath>

typedef long long ll;

using namespace std;

bool solve(ll m, ll r, ll x[], ll b) {

    ll xd = 0;

    for(int i=0; i<m; i++) {
        xd+=abs(x[m/2]-x[i]);
    }

    if(xd <= b) {
        return true;
    }

    for(ll i = 1; i < r-m; i++) {
        xd-=(x[m/2+i-1]-x[i-1]);
        xd+=(x[m/2+i]-x[m/2+i-1])*(m/2);
        xd+=(x[m+i]-x[m/2+i]);
        xd-=(x[m/2+i]-x[m/2+i-1])*(m-m/2);

        if(xd <= b) return true;
    }

    return false;
}

ll besthub(ll r, ll l, ll x[], ll b) {

    ll u = 0;
    ll m;
    ll v = r;

    while(u < v) {
        m = ceil((u+v)/2.0);

        if(solve(m, r, x, b)) {
            u = m;
        }
        else {
            v = m-1;
        }
    }


    return u;

}

Compilation message

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