#include <bits/stdc++.h>
using namespace std;
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
int n, p, q;
cin >> n >> p >> q;
vector<int> a(n + 1);
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
sort(1 + a.begin(), a.end());
auto good = [&](int x) {
int one = 1, two = 1;
vector<vector<int>> dp(n + 1, vector<int>(q + 1));
for(int i = 1; i <= n; ++i) {
while(a[i] - a[one] >= x) {
++one;
}
while(a[i] - a[two] >= x * 2) {
++two;
}
for(int j = 0; j <= q; ++j) {
dp[i][j] = dp[one - 1][j] + 1;
}
for(int j = 0; j < q; ++j) {
if(dp[i][j + 1] > dp[two - 1][j]) {
dp[i][j + 1] = dp[two - 1][j];
}
}
}
return (dp[n][q] <= p);
};
if(n <= p + q) {
cout << -1;
exit(0);
}
int l = 1, r = 1000000000, ans = -1;
while(l <= r) {
int m = (l + r) / 2;
if(good(m)) {
r = m - 1;
ans = m;
}
else {
l = m + 1;
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |