답안 #575434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575434 2022-06-10T12:44:59 Z Huy 구경하기 (JOI13_watching) C++17
0 / 100
5 ms 340 KB
#include<bits/stdc++.h>
//#define int long long
#define pii pair<ll,ll>
#define fi first
#define se second

using namespace std;
using ll = long long;
using ldb = long double;
const int N = (int)5e5+2;
const int maxN = (int)1e5 + 5;
const int mod = 1e9 + 7;
const ll infty = 1e10;

void InputFile()
{
    //freopen("scrivener.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    //freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

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

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

int r1[2005];
int r2[2005];
int dp[2005][2005];
bool Check(int d)
{
    for(int i = 1;i <= n;i++)
    {
        int su = a[i] + d - 1;
        r1[i] = upper_bound(a + i,a + n + 1,su) - a - 1;
        su = a[i] + 2 * d - 1;
        r2[i] = upper_bound(a + i,a + n + 1,su) - a - 1;
    }
    r1[n+1] = r2[n+1] = 0;
    dp[0][0] = 0;
    for(int i = 1;i <= P;i++)
    {
        dp[i][0] = r1[dp[i-1][0]+1];
        if(dp[i][0] >= n) return true;
    }
    for(int j = 1;j <= Q;j++)
    {
        dp[0][j] = r2[dp[0][j-1]+1];
        if(dp[0][j] >= n) return true;
    }
    for(int i = 1;i <= P;i++)
    {
        for(int j = 1;j <= Q;j++)
        {
            dp[i][j] = max(r1[dp[i-1][j]+1],r2[dp[i][j-1]+1]);
            if(dp[i][j] >= n) return true;
        }
    }
    return false;
}

void Solve()
{
    if(P + Q >= n) {cout << P + Q ;return;}
    int low = 1;
    int high = 1e9;
    while(low <= high)
    {
        int mid = (low + high) / 2;
        if(Check(mid)) high = mid - 1;
        else low = mid + 1;
    }
    cout << low;
}

void Debug()
{
    //Main_sub();
    //Naive();
}


int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    int test;
    //cin >> test;
    test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}

/*
13 1
769 514 336 173 181 373 519 338 985 709 729 702 168
12 581
*/

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 340 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -