제출 #1355171

#제출 시각아이디문제언어결과실행 시간메모리
1355171nataliaa구경하기 (JOI13_watching)C++20
100 / 100
130 ms16088 KiB
#include<bits/stdc++.h>
using namespace std;
int n, p, q;
vector<int> a;
bool check(int w){
    int dp[n+1][n+1]={};
    int l1 = 0, l2 = 0;
    for(int i = 1; i<=n; i++){
        for(int j = 0; j <= n; j++) dp[i][j] = 20000;
    }
    for(int i = 1; i <= n; i++){
        while(a[i] - w >= a[l1+1]) l1++;
        while(a[i] - w-w >= a[l2+1]) l2++;
        //cout << l1 <<" "<< l2 << endl;
        for(int j = 0; j <= n; j++){
            dp[i][j] = dp[l2][j]+1;
            if(j!=0) dp[i][j] = min(dp[l1][j-1], dp[l2][j]+1);
        }
        //cout << endl;
    }
    // cout <<"\\";
    // cout << dp[n][p]<<" "<< (int)(dp[n][p]<=q)<<endl;
    
    return (dp[n][p] <=q);
}
int main(){
    cin >> n >> p >> q;
    a.push_back(-1);
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    
    int l, r;
    l = 1, r = 1000000000;
    int ans = r;
    p = min(n, p);

    sort(a.begin(), a.end());
    //for(auto i : a) cout << i << " ";
    //cout << endl;
    while(l<r){
        int m = (l+r)/2;
        //cout << m<<" "<<endl;
        if(check(m)){
            
            r = m;
            ans = m;
        }
        else l = m+1;
        //cout << endl;
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...