Submission #335942

# Submission time Handle Problem Language Result Execution time Memory
335942 2020-12-14T11:06:56 Z aryan12 Rice Hub (IOI11_ricehub) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;

int besthub(int r, int l, int x[], int b) {
    int ans = 1;
    for(int i = 2; i <= r; i++) {
        int left = 1, right = i, best = r;
        int mid;
        while(left <= right) {
            mid = (left + right) / 2;
            int FieldSituated = (mid + i) / 2, cost = 0;
            //cout << "left = " << left << ", right = " << right << ", mid = " << mid << ", FieldSituated = " << FieldSituated << ", cost = ";
            for(int j = mid; j <= i; j++) {
                cost += (abs(x[j] - x[FieldSituated]));
            }
            //cout << cost << endl;
            if(cost <= b) {
                right = mid - 1;
                best = mid;
            }
            else {
                left = mid + 1;
            }
        }
        ans = max(ans, i - best + 1);
    }
    return ans;
}

/*int main() {
    cout << "Input the number of rice fields" << endl;
    int r;
    cin >> r;
    cout << "Input the maximum coordinate" << endl;
    int l;
    cin >> l;
    cout << "Input r numbers, denoting the rice fields" << endl;
    int x[r + 1];
    for(int i = 1; i <= r; i++) {
        cin >> x[i];
    }
    cout << "Input the budget" << endl;
    int b;
    cin >> b;
    cout << besthub(r, l, x, b) << endl;
}
*/

Compilation message

/tmp/ccqKswbu.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