#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, p, q;
std::cin >> n >> p >> q;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
if (p + q >= n) {
std::cout << 1 << "\n";
return 0;
}
sort(a.begin(), a.end());
auto check = [&](int len) {
std::vector<std::vector<std::vector<int>>> dp(n + 1, std::vector<std::vector<int>>(p + 1, std::vector<int>(q + 1)));
dp[0][0][0] = 1;
int p1 = 1, p2 = 1;
// std::cout << "\n";
// std::cout << len << "\n";
for (int i = 1; i <= n; i++) {
while (a[i - 1] - a[p1 - 1] >= len) p1++;
while (a[i - 1] - a[p2 - 1] >= 2 * len) p2++;
// std::cerr << i << " " << p1 << " " << p2 << "\n";
for (int P = 0; P <= p; P++) {
for (int Q = 0; Q <= q; Q++) {
if (P) {
dp[i][P][Q] += dp[i][P - 1][Q];
dp[i][P][Q] += dp[p1 - 1][P - 1][Q];
}
if (Q) {
dp[i][P][Q] += dp[i][P][Q - 1];
dp[i][P][Q] += dp[p2 - 1][P][Q - 1];
}
}
}
}
return dp[n][p][q];
};
// for (int i = 1; i <= 17; i++) std::cerr << check(i) << "\n";
// return 0;
int l = 0, r = 1000000007;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (check(mid)) {
r = mid;
} else {
l = mid;
}
}
std::cout << r << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
5 ms |
332 KB |
Output is correct |
10 |
Correct |
35 ms |
764 KB |
Output is correct |
11 |
Correct |
38 ms |
844 KB |
Output is correct |
12 |
Correct |
99 ms |
1516 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
3 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
191 ms |
3436 KB |
Output is correct |
8 |
Runtime error |
134 ms |
262148 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |