#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;
const int MAXN = 2005;
int n, a, b;
vector<int> nums;
int idx(int val) {
int ans = -1;
int lo = 0, hi = n - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (nums[mid] < val) {
lo = mid + 1;
ans = max(ans, mid);
}
else {
hi = mid - 1;
}
}
return ans;
}
bool check(int mid) {
int dp[MAXN][MAXN];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = (int)1e9;
}
}
for (int i = 0; i < n; i++) {
int cur = idx(nums[i] - 2 * mid + 1);
if (cur == -1) {
dp[i][0] = 1;
}
else {
dp[i][0] = dp[cur][0] + 1;
}
}
for (int i = 0; i < n; i++) {
for (int j = 1; j <= min(a, n); j++) {
int val1 = idx(nums[i] - mid + 1);
int val2 = idx(nums[i] - 2 * mid + 1);
int c1 = INT_MAX, c2 = INT_MAX;
if (val1 == -1) {
c1 = 0;
}
else {
c1 = dp[val1][j - 1];
}
if (val2 == -1) {
c2 = 1;
}
else {
c2 = dp[val2][j] + 1;
}
dp[i][j] = min(c1, c2);
}
}
for (int i = 0; i <= min(a, n); i++) {
if (dp[n - 1][i] <= b) {
return true;
}
}
return false;
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
nums.push_back(temp);
}
sort(nums.begin(), nums.end());
int lo = 1;
int hi = (int)1e9;
int ans = INT_MAX;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (check(mid)) {
ans = min(ans, mid);
hi = mid - 1;
}
else {
lo = mid + 1;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
8 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
16000 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Execution timed out |
1087 ms |
16000 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |