#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = 105;
const int inf = 1e9;
int a[mxN], dp[mxN][mxN], n, s, b, cur;
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];
int x = n, y = n;
for(int j = i + 1; j < n; ++j){
if((a[j] - a[i] + 1) > 2 * cur){
if(x == n) x = j;
}
if((a[j] - a[i] + 1) > cur){
if(y == n) y = j;
}
}
return dp[i][s] = min(f(x, s) + 1, f(y, 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 = 0, en = 1e9 + 7, ans = 0;
while(st <= en){
int mid = st + (en - st) / 2;
cur = mid;
memset(dp, -1, sizeof(dp));
if(f(0, s) <= b){
ans = mid;
en = mid - 1;
}else{
st = mid + 1;
}
}
cout << ans << "\n";
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |