제출 #366311

#제출 시각아이디문제언어결과실행 시간메모리
366311idk321Watching (JOI13_watching)C++11
50 / 100
1086 ms16256 KiB

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 2005;
int dp[N][N];
int n,p, q;
int a[N];

bool poss(ll w)
{
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++) dp[i][j] = 0;
    }
    for (int i = p; i >= 0; i--)
    {
        for (int j = q; j >= 0; j--)
        {

            if (dp[i][j] == n)
            {
                dp[0][0] = n;
            } else
            {
                if (i != 0)
                {
                    int first = a[dp[i][j]];
                    auto it = upper_bound(a, a + n, first + w - 1);

                    it--;
                    dp[i - 1][j] = max<int>(it - a + 1, dp[i - 1][j]);
                }
                if (j != 0)
                {
                    int first = a[dp[i][j]];
                    auto it = upper_bound(a, a + n, first + 2 * w - 1);
                    it--;
                    dp[i][j - 1] = max<int>(it - a + 1, dp[i][j  -1]);
                }
            }
        }
    }

    return dp[0][0] == n;
}

int bs()
{
    int a = 2;
    int b = 1000000000;

    int res = -1;
    while (a <= b)
    {
        int mid = (a + b) / 2;
        if (poss(mid))
        {
            res = mid;
            b = mid - 1;
        } else
        {
            a = mid + 1;
        }
    }

    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> p >> q;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (p + q >= n)
    {
        cout << 1 << "\n";
        return 0;
    }
    sort(a, a + n);

    cout << bs() << "\n";
}

/*
3 1 1
2
11
17
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...