Submission #361512

#TimeUsernameProblemLanguageResultExecution timeMemory
361512RyoPham구경하기 (JOI13_watching)C++14
100 / 100
202 ms16236 KiB
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2005;
const int inf = 1e9 + 9;

int n, P, Q;
int a[maxn];

int dp[maxn][maxn];

void read_input()
{
    cin >> n >> P >> Q;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a + 1, a + n + 1);
}

bool check(int w)
{
    fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), inf);
    dp[0][0] = 0;
    int curs1 = 0, curs2 = 0;
    for(int i = 1; i <= n; ++i)
    {
        while(a[i] - a[curs1 + 1] + 1 > w)
            ++curs1;
        while(a[i] - a[curs2 + 1] + 1 > 2 * w)
            ++curs2;
        for(int j = 0; j <= min(i, P); ++j)
        {
            dp[i][j] = min(dp[i][j], dp[curs2][j] + 1);
            if(j > 0) dp[i][j] = min(dp[i][j], dp[curs1][j - 1]);
        }
    }
    for(int j = 0; j <= min(n, P); ++j)
        if(dp[n][j] <= Q) return true;
    return false;
}

void solve()
{
    int low = 1, high = inf;
    while(low <= high)
    {
        int mid = (low + high) / 2;
        if(check(mid)) high = mid - 1;
        else low = mid + 1;
    }
    cout << low << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...