#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define ar array
const int M = 1e6;
const int N = 26e4 + 20;
const int LOG = 31;
const int INF = 1e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-9;
inline void mm(int &x){x = (x % MOD + MOD) % MOD;}
inline void chmin(int &x, int y){x = min(x, y);}
inline void chmax(int &x, int y){x = max(x, y);}
#pragma GCC optimize("unroll-loops,O3")
void orz(){
int n, a, b;
cin>>n>>a>>b;
a = min(a, n);
int A[n];
for(int i = 0;i < n;i++)cin>>A[i];
sort(A, A + n);
auto koce = [&](int mid) -> bool {
int dp[n + 1][a + 1];
memset(dp, 0x3f, sizeof dp);
dp[0][0] = 0;
int p1 = 0,p2 = 0;
for(int i = 0;i < n;i++){
p1 = max(p1, i);
p2 = max(p2, i);
while(p1 < n && A[i] + mid - 1 >= A[p1])p1++;
while(p2 < n && A[i] + 2 * mid - 1 >= A[p2])p2++;
//cout<<i<<" "<<p1<<" "<<p2<<'\n';
for(int x = 0;x <= a;x++){
if(x < a)chmin(dp[p1][x + 1], dp[i][x]);
chmin(dp[p2][x], dp[i][x] + 1);
}
}
return *min_element(dp[n], dp[n] + a + 1) <= b;
};
koce(4);
int lo = 0, hi = INF;
while(hi - lo > 1){
int mid = (lo + hi) / 2;
//lo = mid;
if(koce(mid))hi = mid;
else lo = mid;
}
cout<<hi;
}
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
int t = 1;
//cin>>t;
while(t--)orz();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |