Submission #1319952

#TimeUsernameProblemLanguageResultExecution timeMemory
1319952aaaaaaaaWatching (JOI13_watching)C++20
100 / 100
979 ms31992 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;
int f(int x){
    vector<vector<int>> dp(n + 5, vector<int>(s + 5, inf));
    for(int j = 0; j <= s; ++j) dp[n][j] = 0;
    for(int j = 0; j <= s; ++j){
        for(int i = n - 1, l = n, l2 = n; i >= 0; --i){
            while(l > i && (a[l - 1] - a[i] + 1) > x) l -= 1;
            while(l2 > i && (a[l2 - 1] - a[i] + 1) > 2 * x) l2 -= 1;
            dp[i][j] = min((j ? dp[l][j - 1] : inf), dp[l2][j] + 1);
        }
    }
    return dp[0][s];
}
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];
    }
    s = min(s, n);
    sort(a, a + n);
    int st = 1, en = 1e9 + 1, ans = 0;
    while(st <= en){
        int mid = st + (en - st) / 2;
        if(f(mid) <= 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...