Submission #861239

# Submission time Handle Problem Language Result Execution time Memory
861239 2023-10-15T17:12:00 Z sleepntsheep Rice Hub (IOI11_ricehub) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include "ricehub.h"

using namespace std;
#define ALL(x) x.begin(), x.end()
#define N 100005
using ll = long long;

int n, l, z = -1;
ll b, p[N], a[N];

int optimal_hub(int l, int r)
{
    return (l+r)/2;
}

ll sum(int l, int r)
{
    return p[r] - p[l-1];
}

ll need_budget(int l, int r, int h)
{
    if (h < l || r < h) return 1e18;
    return a[h] * (h-l+1) - a[h] * (r-h) + sum(h+1, r) - sum(l, h);
}

ll need_budget(int l, int r)
{
    return min({need_budget(l, r, optimal_hub(l, r)),
            need_budget(l, r, optimal_hub(l, r) + 1), 
            need_budget(l, r, optimal_hub(l, r) - 1)});
}

ll besthub(int r, int l, int *a, ll b)
{
    for (int i = 1; i <= n; ++i) 
    {
        p[i] = p[i-1] + a[i];
        int l = 1, r = i;
        while (l <= r)
        {
            int y = (l+r)/2;
            if (need_budget(y, i) <= b)
                z = max(z, i-y+1), r = y - 1;
            else l = y + 1;
        }
    }
    return z;
}



Compilation message

ricehub.cpp:42:4: error: ambiguating new declaration of 'll besthub(int, int, int*, ll)'
   42 | ll besthub(int r, int l, int *a, ll b)
      |    ^~~~~~~
In file included from ricehub.cpp:9:
ricehub.h:1:5: note: old declaration 'int besthub(int, int, int*, long long int)'
    1 | int besthub(int R, int L, int X[], long long B);
      |     ^~~~~~~