제출 #722385

#제출 시각아이디문제언어결과실행 시간메모리
722385hyakup구경하기 (JOI13_watching)C++17
100 / 100
124 ms16056 KiB
#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 2010;
 
int pos[maxn];
 
int dp[maxn][maxn];
int n, p, q; 
 
bool check( int x ){
    
    for( int j = 0; j < maxn; j++ ) dp[0][j] = 0;
    
    int k1 = 0, k2 = 0;
    
    for( int i = 1; i <= n; i++ ){
        
        while( pos[k1 + 1] < pos[i] - x + 1 ) k1++;
        while( pos[k2 + 1] < pos[i] - 2*x + 1 ) k2++;
        
        dp[i][0] = dp[k2][0] + 1;
        
        for( int j = 1; j <= p; j++ ){
            
            dp[i][j] = min( dp[k1][j - 1], dp[k2][j] + 1 );
        }
    }
    
    if( dp[n][p] <= q ) return true;
    return false;
}
 
int bs(){
    
    int ini = 1, fim = 1000000010;
    
    while( ini < fim ){
        
        int mid = ( ini + fim )/2;
        
        if( check(mid) ) fim = mid;
        else ini = mid + 1;
    }
    
    return fim;
}
 
int main(){
    
    cin >> n >> p >> q;
    
    if( p + q >= n ){
        
        cout << 1;
        
        return 0;
    }
    
    for( int i = 1; i <= n; i++ ) cin >> pos[i];
    
    sort( pos, pos + n + 1 );
    
    int resp = bs();
    
    cout << resp;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...