#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl "\n"
#define vec vector<ll>
#define vecvec vector<vector<ll>>
using namespace std;
/*#define FileName ""
string Ghhhh = ".in";
string Ghhhhh = ".out";
ifstream Girdi(FileName + Ghhhh);
ofstream Cikti(FileName + Ghhhhh);
#define cin Girdi
#define cout Cikti*/
const ll INF = 1e15;
ll n,a,b;
vector<ll> times;
inline bool control(ll max_dif){
ll start = 0;
for(ll i = 0 ; i < n ; i++){
if(times[i] - times[start] > max_dif or i - start + 1 > b){
if(i - start < a) return 0;
start = i;
}
}
if(n - start < a) return 0;
return 1;
}
inline void solve(){
cin >> n >> a >> b;
times.resize(n);
for(ll i = 0 ; i < n ; i++) cin >> times[i];
sort(times.begin(), times.end());
ll l = 0, r = times[n-1] - times[0];
ll ans = r;
while(l < r){
ll mid = (l + r) / 2;
if(control(mid)){
ans = mid;
r = mid;
}else l = mid+1;
}
if(control(l)) ans = l;
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |