Submission #1236664

#TimeUsernameProblemLanguageResultExecution timeMemory
1236664fauntleroyRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
int besthub(int R, int L, int x[], ll B) {
    int n = R;
    vector<ll> d(n - 1);
    for (int i = 0; i < n - 1; ++i)
        d[i] = x[i + 1] - x[i];
    vector<ll> pref(n - 1, 0);
    pref[0] = d[0];
    for (int i = 1; i < n - 1; ++i)
        pref[i] = pref[i - 1] + d[i];

    int l = 0, r = n;
    int ans = 0;
    while (l <= r) {
        int k = (l + r) >> 1;
        --k;    
        if (k == 0) {
            ans = max(ans, 1);
            l = 2;
            continue;
        }
        int l1 = 0, r1 = n - k - 1;
        ll mn = 1e9;
        
        for (int i = 0; i < n - k; ++i) {
            ll s = pref[i + k - 1] - (i > 0 ? pref[i - 1] : 0);
            if (s < mn) {
                l1 = i, r1 = i + k - 1;
                mn = s;
            }
        }
        //cout << l1 << ' ' << r1 << ' ' << " " << ' ' << k << '\n';
        int pos = (l1 > 0 ? pref[l1 - 1] : 0) + 1 + mn / 2;
        ll d = 0;
        for (int i = l1; i <= r1 + 1; ++i)
            d += abs(pos - x[i]);
        //cout << pos<<' '<<d << '\n';
        ++k;
        if (d > B)
            r = k - 1;
        else
            l = k + 1, ans = max(ans, k);
    }
    return ans;
}

Compilation message (stderr)

ricehub.cpp:1:36: error: 'll' has not been declared
    1 | int besthub(int R, int L, int x[], ll B) {
      |                                    ^~
ricehub.cpp: In function 'int besthub(int, int, int*, int)':
ricehub.cpp:3:12: error: 'll' was not declared in this scope
    3 |     vector<ll> d(n - 1);
      |            ^~
ricehub.cpp:3:5: error: 'vector' was not declared in this scope
    3 |     vector<ll> d(n - 1);
      |     ^~~~~~
ricehub.cpp:3:16: error: 'd' was not declared in this scope
    3 |     vector<ll> d(n - 1);
      |                ^
ricehub.cpp:6:16: error: 'pref' was not declared in this scope
    6 |     vector<ll> pref(n - 1, 0);
      |                ^~~~
ricehub.cpp:17:19: error: 'max' was not declared in this scope
   17 |             ans = max(ans, 1);
      |                   ^~~
ricehub.cpp:22:11: error: expected ';' before 'mn'
   22 |         ll mn = 1e9;
      |           ^~~
      |           ;
ricehub.cpp:25:15: error: expected ';' before 's'
   25 |             ll s = pref[i + k - 1] - (i > 0 ? pref[i - 1] : 0);
      |               ^~
      |               ;
ricehub.cpp:26:21: error: 'mn' was not declared in this scope; did you mean 'n'?
   26 |             if (s < mn) {
      |                     ^~
      |                     n
ricehub.cpp:26:17: error: 's' was not declared in this scope
   26 |             if (s < mn) {
      |                 ^
ricehub.cpp:32:53: error: 'mn' was not declared in this scope; did you mean 'n'?
   32 |         int pos = (l1 > 0 ? pref[l1 - 1] : 0) + 1 + mn / 2;
      |                                                     ^~
      |                                                     n
ricehub.cpp:33:11: error: expected ';' before 'd'
   33 |         ll d = 0;
      |           ^~
      |           ;
ricehub.cpp:35:18: error: 'abs' was not declared in this scope; did you mean 'ans'?
   35 |             d += abs(pos - x[i]);
      |                  ^~~
      |                  ans
ricehub.cpp:41:30: error: 'max' was not declared in this scope
   41 |             l = k + 1, ans = max(ans, k);
      |                              ^~~