제출 #95281

#제출 시각아이디문제언어결과실행 시간메모리
95281dalgerok구경하기 (JOI13_watching)C++14
100 / 100
289 ms16248 KiB
#include<bits/stdc++.h>
using namespace std;


const int N = 2005;




int n, p, q, a[N], d1[N], d2[N], dp[N][N];

inline bool check(int w){
    for(int i = 1; i <= n; i++){
        d1[i] = lower_bound(a + 1, a + n + 1, a[i] - w + 1) - a;
        d2[i] = lower_bound(a + 1, a + n + 1, a[i] - 2 * w + 1) - a;
    }
    memset(dp, 63, sizeof(dp));
    for(int i = 0; i <= p; i++){
        dp[0][i] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= p; j++){
            if(j > 0){
                dp[i][j] = dp[d1[i] - 1][j - 1];
            }
            dp[i][j] = min(dp[i][j], dp[d2[i] - 1][j] + 1);
        }
    }
    return dp[n][p] <= q;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> p >> q;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    if(p + q >= n){
        return cout << 1, 0;
    }
    sort(a + 1, a + n + 1);
    int l = 1, r = 1e9;
    while(r - l > 1){
        int mid = (r + l) >> 1;
        if(check(mid)){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    if(check(l)){
        cout << l;
    }
    else{
        cout << r;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...