Submission #1319924

#TimeUsernameProblemLanguageResultExecution timeMemory
1319924aaaaaaaaWatching (JOI13_watching)C++20
50 / 100
882 ms327680 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = 2005;
const int inf = 2e18 + 4;
int a[mxN], n, s, b, cur;
vector<vector<int>> dp;
int find(int i, int x){
    int st = i + 1, en = n - 1, ans = n;
    while(st <= en){
        int mid = st + (en - st) / 2;
        if((a[mid] - a[i] + 1) > x){
            en = mid - 1;
            ans = mid;
        }else{
            st = mid + 1;
        }
    }
    return ans;
}
int f(int i, int s){
    if(s < 0) return inf;
    if(i == n) return 0;
    if(dp[i][s] != -1) return dp[i][s];
    return dp[i][s] = min(f(find(i, 2 * cur), s) + 1, f(find(i, cur), s - 1));
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> s >> b;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a, a + n);
    int st = 1, en = 1e9 + 7, ans = 0;
    while(st <= en){
        int mid = st + (en - st) / 2;
        cur = mid;
        dp = vector<vector<int>>(n + 2, vector<int>(s + 2, -1));
        if(f(0, s) <= b){
            ans = mid;
            en = mid - 1;
        }else{
            st = mid + 1;
        }
    }
    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...