제출 #1292101

#제출 시각아이디문제언어결과실행 시간메모리
1292101torment구경하기 (JOI13_watching)C++20
100 / 100
121 ms16168 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int dp[N][N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, p, q;
    cin >> n >> p >> q;
    vector<int>a(n + 1, -1e9);
    for(int i = 1;i <= n;++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if(p + q >= n){
        cout << "1\n";
        return 0;
    }
    else{
        int l = 1, r = 1e9, ans = 1e9;
        while(l <= r){
            int mid = (l + r) / 2;
            for(int i = 1;i < N;++i){
                for(int j = 0;j < N;++j){
                    dp[i][j] = 1e9;
                }
            }
            for(int i = 1;i <= n;++i){
                int pos1 = lower_bound(a.begin(), a.end(), a[i] - mid + 1) - a.begin();
                pos1--;
                int pos2 = lower_bound(a.begin(), a.end(), a[i] - 2 * mid + 1) - a.begin();
                pos2--;
                for(int j = 0;j <= p;++j){
                    dp[i][j] = dp[pos2][j] + 1;
                    if(j)dp[i][j] = min(dp[i][j], dp[pos1][j - 1]);
                }
            }
            if(dp[n][p] <= q){
                ans = mid;
                r = mid - 1;
            }
            else{
                l = mid + 1;
            }
        }
        cout << ans << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...