#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 2005;
int N, P, Q;
int A[NMAX];
int dp[NMAX][NMAX];
bool Check (int W) {
for (int i = 0; i <= N; ++ i )
for (int j = 0; j <= N; ++ j )
dp[i][j] = -1;
dp[0][0] = 0;
int last_p = 1, last_q = 1;
for (int i = 1; i <= N; ++ i ) {
while (last_p < i && A[i] - A[last_p] + 1 > W)
++ last_p;
while (last_q < i && A[i] - A[last_q] + 1 > 2*W)
++ last_q;
dp[i][0] = dp[last_q-1][0] + 1;
for (int j = 1; j <= min(P, N); ++ j )
dp[i][j] = min(dp[last_q-1][j] + 1, dp[last_p-1][j-1]);
}
for (int i = 0; i <= min(P, N); ++ i )
if (dp[N][i] <= Q)
return 1;
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> P >> Q;
for (int i = 1; i <= N; ++ i )
cin >> A[i];
sort(A+1, A+N+1);
int st = 1, dr = 1e9;
int ans = 0;
while (st <= dr) {
int mij = (st + dr) / 2;
if (Check(mij)) {
ans = mij;
dr = mij - 1;
}
else st = mij + 1;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
16024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |