#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);
};
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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
866 ms |
40688 KB |
Output is correct |
6 |
Correct |
903 ms |
40388 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
260 ms |
12448 KB |
Output is correct |
4 |
Correct |
15 ms |
1012 KB |
Output is correct |
5 |
Runtime error |
97 ms |
262144 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |