Submission #1309277

#TimeUsernameProblemLanguageResultExecution timeMemory
1309277bobothenubchickWatching (JOI13_watching)C++20
0 / 100
588 ms327680 KiB
# include <bits/stdc++.h>
using namespace std;
#define int long long
int n,p,q,a[2005],dp[2005][100005];

bool check(int w)
{
    for (int i =0; i <= n; i++)
    {
        for (int j = 0; j <= q; j++)
        {
            dp[i][j] = n+1;
        }
    }
    dp[0][0] = 0;
    int j = 1, k = 1;
    for (int i = 1; i <= n; i++)
    {   
        while (j <= i and a[i]-a[j]+1 > w)
        {
            j++;
        }
        while (k <= i and a[i]-a[k]+1 > w*2)
        {
            k++;
        }
        for (int t = 0; t <= p; t++)
        {
            if (t > 0) dp[i][t] = min(dp[i][t],dp[j-1][t-1]);
            dp[i][t] = min(dp[i][t],dp[k-1][t]+1);
        }
    }
    bool checky = false;
    for (int i = 0; i <= p; i++)
    {
        // cerr << dp[n][i] << " ";
        if (dp[n][i] <= q) checky = true;
    }
    return checky;
}

int bs()
{
    int l = 1, r = a[n], mid;
    while (l <= r )
    {
        mid = (l+r)/2;
        if (check(mid)) r = mid-1;
        else l = mid+1;
    }
    return l;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> p >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    cout << bs();
    // cout << check(3);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...