#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N, P, Q; cin >> N >> P >> Q;
P = min(P, N);
Q = min(Q, N);
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
sort(A.begin(), A.end());
vector dp(P + 1, vector<int>(Q + 1));
vector<array<int, 2>> nxt(N);
auto check = [&](int md) {
nxt[N - 1][0] = nxt[N - 1][1] = N - 1;
for (int i = N - 2; ~i; --i) {
for (int j = 1; j <= 2; ++j) {
int &p = nxt[i][j - 1];
p = nxt[i + 1][j - 1];
while (A[p] - A[i] >= j * md) {
--p;
}
}
}
for (int i = 0; i <= P; ++i) {
fill(dp[i].begin(), dp[i].end(), -1);
}
dp[0][0] = 0;
for (int i = 0; i <= P; ++i) {
for (int j = 0; j <= Q; ++j) {
if (dp[i][j] != -1) {
if (dp[i][j] == N) {
return true;
}
if (i + 1 <= P) {
dp[i + 1][j] = max(dp[i + 1][j], nxt[dp[i][j]][0] + 1);
}
if (j + 1 <= Q) {
dp[i][j + 1] = max(dp[i][j + 1], nxt[dp[i][j]][1] + 1);
}
}
}
}
return false;
};
int l = 0, r = 1e9, res = 1e9;
while (l <= r) {
int md = (l + r) / 2;
if (check(md)) {
res = md;
r = md - 1;
} else {
l = md + 1;
}
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
32 ms |
9308 KB |
Output is correct |
4 |
Correct |
8 ms |
1176 KB |
Output is correct |
5 |
Correct |
2 ms |
992 KB |
Output is correct |
6 |
Correct |
32 ms |
16220 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
860 KB |
Output is correct |
9 |
Correct |
7 ms |
860 KB |
Output is correct |
10 |
Correct |
10 ms |
1116 KB |
Output is correct |
11 |
Correct |
5 ms |
1112 KB |
Output is correct |
12 |
Correct |
39 ms |
4188 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |