Submission #1355187

#TimeUsernameProblemLanguageResultExecution timeMemory
1355187lizi14구경하기 (JOI13_watching)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define ss second
#define ina insert
#define pb push_back
int n,p,q;
vector<int>x(2005);
bool check(int w){
    int dp[n+1][p+1];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=p; j++){
            if(i==0){
                dp[i][j]=0;
            }
            else dp[i][j]=1e8;
        }
    }
    int l_pa=0;
    int l_did=0;
    //dp[0][0]=1;
    for(int i=1; i<=n; i++){
        while(l_pa+1<=n && x[i]-w>=x[l_pa+1])l_pa++;
        while(l_did+1<=n && x[i]-2*w>=x[l_did+1])l_did++;
        
        for(int j=0; j<=p; j++){
            if(j>=1)dp[i][j]=min(dp[l_pa][j-1],dp[i][j]);
            dp[i][j]=min(dp[i][j],dp[l_did][j]+1);
            
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    if(dp[n][p]<=q){
        return true;
    }
    return false;
}

signed main(){
    cin>>n>>p>>q;
    //x.resize(n + 1);
    for(int i=1; i<=n; i++){
        cin>>x[i];
    }
    x[0]=-1;
    sort(x.begin(),x.end());
    int l=1,r=1e9;
    int ans=-1;
    while(l<=r){
        int mid=(l+r)/2;
        int h=check(mid);
        //cout<<h<<" "<<mid<<endl;
        if(h){
            r=mid-1;
            ans=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<ans<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...