Submission #1355196

#TimeUsernameProblemLanguageResultExecution timeMemory
1355196putuputu구경하기 (JOI13_watching)C++20
0 / 100
1022 ms327680 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, q, p;
vector<int> a(n);
bool check(int w){
    vector<vector<int>> dp(n+1, vector<int>(q+1));
    for(int i=0; i<=n; i++){
        for(int j=0; j<=q; j++){
            if(i==0){
                dp[i][j]=0;
            }else{
                dp[i][j]=LLONG_MAX;
            }
        }
    }
    int r=0, rr=0;
    for(int i=1; i<=n; i++){
        while(a[r+1]<=a[i]-w){
            r++;
        }
        while(a[rr+1]<=a[i]-2*w){
            rr++;
        }
        for(int j=0; j<=q; j++){
            if(j==0){
                dp[i][j]=dp[rr][j]+1;
            }else{
                dp[i][j]=min(dp[r][j-1], dp[rr][j]+1);
            }
        }
    }
    if(dp[n][q]<=p){
        return true;
    }else{
        return false;
    }
}
signed main(){
    cin >> n >> q >> p;
    a.resize(n+1);
    a[0]=0;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int l=1, r=1e9;
    int ans=-1;
    while(l<r){
        int m=(l+r)/2;
        if(check(m)==true){
            ans=m;
            r=m;
        }else{
            l=m+1;
        }
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...