This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |