Submission #1329081

#TimeUsernameProblemLanguageResultExecution timeMemory
1329081hrantsargsyanRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
#include <iostream>

using namespace std;

const int N = 2e5 + 5;

long long pref[N];
int n;

int check(int x, B)
{
    int l = 1, r = x;
    while (r <= n)
    {
        if ((pref[r] - pref[r - x / 2]) - (pref[l + x / 2 - 1] - pref[l - 1]) <= B)
        {
            return true;
        }
        ++l;
        ++r;
    }
    return false;
}

int besthub(int R, int L, int X[], long long B)
{
    n = R;
    for (int i = 1;i <= n;++i)
    {
        cin >> X[i];
    }
    pref[0] = 0;
    for (int i = 1;i <= n;++i)
    {
        pref[i] = pref[i - 1] + X[i];
    }
    int l = 1, r = n;
    int ans = -1;
    while (l <= r)
    {
        int mid = (l + r) / 2;
        if (check(mid, B))
        {
            ans = max(ans, mid);
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }
    cout << ans << endl;
}

Compilation message (stderr)

ricehub.cpp:10:18: error: 'B' has not been declared
   10 | int check(int x, B)
      |                  ^
ricehub.cpp: In function 'int check(int, int)':
ricehub.cpp:15:82: error: 'B' was not declared in this scope
   15 |         if ((pref[r] - pref[r - x / 2]) - (pref[l + x / 2 - 1] - pref[l - 1]) <= B)
      |                                                                                  ^
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:53:1: warning: no return statement in function returning non-void [-Wreturn-type]
   53 | }
      | ^