// problem1.cpp
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, l, r) for(int i = l; i <= r; i++)
#define FORD(i, l, r) for(int i = l; i >= r; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sp(x) setprecision(x) << fixed
#define db double
#define ldb long double
#define ff first
#define ss second
#define pb push_back
#define ins insert
const int N = 2e3 + 5;
int n, p, q, a[N];
bool check(int w){
vector<int> small_cam(n + 1), big_cam(n + 1);
function<int(int)> find_pos = [&](int x){
int l = 1, r = n, ans = n + 1;
while(l <= r){
int m = (l + r) >> 1;
if(a[m] <= x){
ans = m;
l = m + 1;
}
else r = m - 1;
}
return ans;
};
FOR(i, 1, n){
small_cam[i] = find_pos(a[i] + w - 1);
big_cam[i] = find_pos(a[i] + 2 * w - 1);
//cerr << "small[" << i << "]: " << small_cam[i] << "\n";
//cerr << "big[" << i << "]: " << big_cam[i] << "\n";
}
vector<vector<int>> dp(p + 5, vector<int>(q + 5, 0));
FOR(i, 0, p)FOR(j, 0, q){
if(i > 0)dp[i][j] = max(dp[i][j], small_cam[dp[i - 1][j] + 1]);
if(j > 0)dp[i][j] = max(dp[i][j], big_cam[dp[i][j - 1] + 1]);
if(dp[i][j] >= n) return true;
}
return dp[p][q] == n;
}
void solve(){
cin >> n >> p >> q;
FOR(i, 1, n) cin >> a[i];
sort(a + 1, a + 1 + n);
int l = 1, r = 1e9, ans = r;
//check(4);
while(l <= r){
int m = (l + r) >> 1;
if(check(m)){
ans = m;
r = m - 1;
}
else l = m + 1;
}
cout << ans << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |