#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
vector<vector<vector<bool> > > dp(105, vector<vector<bool>>(105, vector<bool>(105)));
int main() {
int n, p, q;
cin >> n >> p >> q;
p = min(n, p);
q = min(n, q);
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
sort(1+all(v));
auto f = [&](int mid) {
for(int i=0; i<=n; i++)
for(int j=0; j<=p; j++)
for(int k=0; k<=q; k++) dp[i][j][k] = 0;
dp[0][0][0] = 1;
for(int i=1; i<=n; i++) {
for(int j=0; j<=p; j++) {
for(int k=0; k<=q; k++) {
if(j) {
int l=1, r=i, pos=i;
while(l <= r) {
int m = (l + r) / 2;
if(v[i] - v[m] < mid) pos = m, r = m - 1;
else l = m + 1;
}
if(dp[pos-1][j-1][k]) dp[i][j][k] = 1;
}
if(k) {
int l=1, r=i, pos=i;
while(l <= r) {
int m = (l + r) / 2;
if(v[i] - v[m] < 2ll * mid) pos = m, r = m - 1;
else l = m + 1;
}
if(dp[pos-1][j][k-1]) dp[i][j][k] = 1;
}
}
}
}
for(int i=0; i<=p; i++)
for(int j=0; j<=q; j++)
if(dp[n][i][j]) return 1;
return 0;
};
int l=1, r=1e9, ans = 1e9;
while(l <= r) {
int mid = (l + r) / 2;
if(f(mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
59 ms |
1116 KB |
Output is correct |
5 |
Correct |
60 ms |
1196 KB |
Output is correct |
6 |
Correct |
768 ms |
1364 KB |
Output is correct |
7 |
Correct |
4 ms |
1112 KB |
Output is correct |
8 |
Correct |
9 ms |
1116 KB |
Output is correct |
9 |
Correct |
9 ms |
1216 KB |
Output is correct |
10 |
Correct |
73 ms |
1192 KB |
Output is correct |
11 |
Correct |
80 ms |
1208 KB |
Output is correct |
12 |
Correct |
197 ms |
1112 KB |
Output is correct |
13 |
Correct |
4 ms |
1116 KB |
Output is correct |
14 |
Correct |
4 ms |
996 KB |
Output is correct |
15 |
Correct |
5 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
2140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |