Submission #1329272

#TimeUsernameProblemLanguageResultExecution timeMemory
1329272nminhnguyenleWatching (JOI13_watching)C++20
0 / 100
89 ms31916 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define inf LLONG_MAX/20
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define fr front
#define bk back
#define fi first
#define se second

int n,p,q;
vector<int> a(2005);
int dp[2005][2005];

// motivation for DP: 
/*
dp[i][j] = the min number of large cameras that we can use when we have taken i lanes using
j small cameras 
*/


signed main() {
	fastio();
    cin>>n>>p>>q;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    p=min(p,n);
    q=min(q,n);
    sort(a.begin(),a.begin()+n);
    int l=1,r=1e9,ans=1e9;
    while(l<r-1){
        // binary searching on w
        int mid=(l+r)/2;
        for(int i=0;i<2005;i++){
            for(int j=0;j<2005;j++){
                dp[i][j]=inf;
            }
        }
        dp[0][0]=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<=p;j++){
                // 1st case: the number of large cameras required > q
                if(dp[i][j]>q) continue;
                // suppose we have a w already (w=mid)
                // suppose we take a small camera
                // range: a[i]->a[i]+mid
                int s_range=lower_bound(a.begin(),a.begin()+n,a[i]+mid)-a.begin(); 
                if(j+1<=p) dp[s_range][j+1]=min(dp[s_range][j+1],dp[i][j]);
                int l_range=lower_bound(a.begin(),a.begin()+n,a[i]+2*mid)-a.begin();
                dp[l_range][j]=min(dp[l_range][j],dp[i][j]+1);
            }
        }
        bool flag=0;
        for(int i=0;i<=p;i++){
            if(dp[n][i]<=q){
                flag=1;
                break;
            }
        }
        if(flag){
            ans=min(ans,mid);
            r=mid;
        }
        else{
            l=mid;
        }
    }
    cout<<ans;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...