Submission #688588

#TimeUsernameProblemLanguageResultExecution timeMemory
688588four_specksWatching (JOI13_watching)C++17
100 / 100
298 ms16332 KiB
#include <bits/stdc++.h>

using namespace std;

namespace
{
} // namespace

void solve()
{
    int n, p, q;
    cin >> n >> p >> q;

    p = min(p, n);
    q = min(q, n);

    vector<long> a(n);
    for (long &x : a)
        cin >> x;
    sort(a.begin(), a.end());

    auto check = [&](long mid) -> bool
    {
        vector dp(n + 1, vector<int>(p + 1));
        for (int i = 0; i < n; i++)
        {
            int
                pos1 = (int)(upper_bound(a.begin(), a.end(), a[i] - mid) - a.begin()),
                pos2 = (int)(upper_bound(a.begin(), a.end(), a[i] - 2 * mid) - a.begin());

            dp[i + 1][0] = dp[pos2][0] + 1;
            for (int j = 0; j < p; j++)
                dp[i + 1][j + 1] = min(dp[pos1][j], dp[pos2][j + 1] + 1);
        }

        return dp[n][p] <= q;
    };

    long lo = 1, hi = 1'000'000'000;
    while (lo < hi)
    {
        long mid = (lo + hi) / 2;
        if (check(mid))
            hi = mid;
        else
            lo = mid + 1;
    }

    cout << lo << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...