#include <bits/stdc++.h>
using namespace std;
namespace
{
} // namespace
void solve()
{
int n, p, q;
cin >> n >> p >> q;
p = min(p, n);
q = min(q, n);
vector<long> a(n);
for (long &x : a)
cin >> x;
sort(a.begin(), a.end());
auto check = [&](long mid) -> bool
{
vector dp(n + 1, vector<int>(p + 1));
for (int i = 0; i < n; i++)
{
int
pos1 = (int)(upper_bound(a.begin(), a.end(), a[i] - mid) - a.begin()),
pos2 = (int)(upper_bound(a.begin(), a.end(), a[i] - 2 * mid) - a.begin());
dp[i + 1][0] = dp[pos2][0] + 1;
for (int j = 0; j < p; j++)
dp[i + 1][j + 1] = min(dp[pos1][j], dp[pos2][j + 1] + 1);
}
return dp[n][p] <= q;
};
long lo = 1, hi = 1'000'000'000;
while (lo < hi)
{
long mid = (lo + hi) / 2;
if (check(mid))
hi = mid;
else
lo = mid + 1;
}
cout << lo << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
221 ms |
12440 KB |
Output is correct |
4 |
Correct |
289 ms |
16332 KB |
Output is correct |
5 |
Correct |
15 ms |
1116 KB |
Output is correct |
6 |
Correct |
298 ms |
16284 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
21 ms |
1472 KB |
Output is correct |
9 |
Correct |
110 ms |
6648 KB |
Output is correct |
10 |
Correct |
279 ms |
15444 KB |
Output is correct |
11 |
Correct |
18 ms |
1108 KB |
Output is correct |
12 |
Correct |
132 ms |
8148 KB |
Output is correct |
13 |
Correct |
7 ms |
532 KB |
Output is correct |
14 |
Correct |
7 ms |
592 KB |
Output is correct |
15 |
Correct |
8 ms |
560 KB |
Output is correct |