#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")
int n;
int A[N];
vector<int> g[N];
int up[N][LOG];
int d[N];
void dfs(int x,int p){
up[x][0] = p;
for(int i = 1;i < LOG;i++)up[x][i] = up[up[x][i - 1]][i - 1];
for(auto u: g[x]){
if(u == p)continue;
d[u] = d[x] + 1;
dfs(u, x);
}
}
int lca(int a,int b){
if(d[a] < d[b])swap(a, b);
int k = d[a] - d[b];
for(int i = 0;i < LOG;i++){
if((1 << i) & k)a = up[a][i];
}
if(a == b)return a;
for(int i = LOG - 1;i >= 0;i--){
if(up[a][i] != up[b][i]){
a = up[a][i];
b = up[b][i];
}
}
return up[a][0];
}
int qry(int a,int b){
int l = lca(a, b);
return d[a] + d[b] - 2 * d[l];
}
int p[N];
int fnd(int x){
if(p[x] == x)return x;
return p[x] = fnd(p[x]);
}
void orz(){
int n, a, b;
cin>>n>>a>>b;
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... |