// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
#include <numeric>
#include <stack>
#include <chrono>
using namespace std;
void fast_io(){
// freopen("", "r", stdin);
// freopen("", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(); cout.tie();
cout << setprecision(9);
}
#define int long long
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
const int N = 2e3 + 5;
int dp[N][N], sm[N], lg[N];
void solve() {
int n, p, q; cin >> n >> p >> q;
int a[n + 1];
for (int i = 1; i <= n; i++){
cin >> a[i];
}
if (p + q >= n){
cout << 1 << endl;
return;
}
sort(a + 1, a + n + 1);
int l = 0, r = a[n] - a[1] + 1;
while (r - l > 1){
int w = (l + r) / 2;
sm[n + 1] = lg[n + 1] = n;
for (int i = 0 ; i <= p; i++){
for (int j = 0; j <= q; j++){
dp[i][j] = 0;
}
}
for (int i = 1; i <= n; i++){
for (int j = i; j <= n; j++){
if (a[j] - a[i] < w) sm[i] = j;
if (a[j] - a[i] < 2 * w) lg[i] = j;
}
}
for (int i = 0; i <= p; i++){
for (int j = 0; j <= q; j++){
if (i != 0){
dp[i][j] = max(dp[i][j], sm[dp[i - 1][j] + 1]);
}
if (j != 0){
dp[i][j] = max(dp[i][j], lg[dp[i][j - 1] + 1]);
}
}
}
if (dp[p][q] == n) r = w;
else l = w;
}
cout << r << endl;
return;
}
signed main() {
fast_io();
srand(chrono::steady_clock::now().time_since_epoch().count());
int tc = 1;
// cin />> tc;
while (tc--) solve();
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |