#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 2e3 + 10;
int n, p, q, a[maxn];
int dp[2][maxn];
int nexlow[maxn], nexhig[maxn];
bool check(int w){
for (int i = 0; i < n; i++){
nexlow[i] = lower_bound(a, a + n, a[i] + w) - a - 1;
nexhig[i] = lower_bound(a, a + n, a[i] + 2 * w) - a - 1;
}
nexlow[n] = nexhig[n] = n - 1;
for (int i = 0; i <= p; i++){
int x = i % 2;
for (int j = 0; j <= q; j++){
dp[x][j] = -1;
if (i > 0)
dp[x][j] = max(dp[x][j], nexlow[dp[1 - x][j] + 1]);
if (j > 0)
dp[x][j] = max(dp[x][j], nexhig[dp[x][j - 1] + 1]);
}
}
return (dp[p%2][q] == n - 1);
}
int main(){
ios_base::sync_with_stdio (false);
cin >> n >> p >> q;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
if (p + q >= n)
return cout << 1 << endl, 0;
int lo = 1, hi = 1000000000 + 1;
while (hi - lo > 1){
int mid = (lo + hi) >> 1;
if (check(mid) == true)
hi = mid;
else
lo = mid;
}
cout << hi << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
8 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
1 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
25 ms |
380 KB |
Output is correct |
9 |
Correct |
25 ms |
504 KB |
Output is correct |
10 |
Correct |
37 ms |
432 KB |
Output is correct |
11 |
Correct |
40 ms |
376 KB |
Output is correct |
12 |
Correct |
187 ms |
504 KB |
Output is correct |
13 |
Correct |
9 ms |
376 KB |
Output is correct |
14 |
Correct |
9 ms |
376 KB |
Output is correct |
15 |
Correct |
9 ms |
376 KB |
Output is correct |