Submission #1216734

#TimeUsernameProblemLanguageResultExecution timeMemory
1216734takoshanavaRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
int besthub(int r, int l, int x[], int b) {
    vector<int> pref(r + 1, 0);
    for (int i = 0; i < r; ++i) {
        pref[i + 1] = pref[i] + x[i];
    }

    int res = 1;
    int ll = 1, rr = r;

    while (ll <= rr) {
        int mid = (ll + rr) / 2;
        bool ok = false;

        for (int i = 0; i + mid <= r; ++i) {
            int s = i;
            int t = i + mid - 1;
            int p = (s + t) / 2;
            int rp = x[p];

            int lcnt = p - s;
            int lsum = pref[p] - pref[s];

            int rcnt = t - p;
            int rsum = pref[t + 1] - pref[p + 1];

            int cost = (rp * lcnt - lsum) + (rsum - rp * rcnt);

            if (cost <= b) {
                ok = true;
                break;
            }
        }

        if (ok) {
            res = x[mid - 1];
            ll = mid + 1;
        } else {
            rr = mid - 1;
        }
    }

    return res;
}

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, int)':
ricehub.cpp:2:5: error: 'vector' was not declared in this scope
    2 |     vector<int> pref(r + 1, 0);
      |     ^~~~~~
ricehub.cpp:2:12: error: expected primary-expression before 'int'
    2 |     vector<int> pref(r + 1, 0);
      |            ^~~
ricehub.cpp:4:9: error: 'pref' was not declared in this scope
    4 |         pref[i + 1] = pref[i] + x[i];
      |         ^~~~
ricehub.cpp:21:24: error: 'pref' was not declared in this scope
   21 |             int lsum = pref[p] - pref[s];
      |                        ^~~~