// watching.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <algorithm>
#include <iostream>
using namespace std;
int arr[2005];
int n, p, q;
int dp[2005][100005];
bool check(int mid)
{
for (int i = 1; i <= n; i++)
{
for (int j = 0; j <= p; j++)
{
dp[i][j] = 1000000000;
}
}
for (int i = 1; i <= n; i++)
{
int j1 = i - 1;
while (j1 >= 1 && arr[i] - arr[j1] + 1 <= mid) j1--;
int j2 = j1;
while (j2 >= 1 && arr[i] - arr[j2] + 1 <= 2 * mid)j2--;
// cout << j1 << " " << j2 << endl;
for (int c = 0; c <= p; c++)
{
if (c > 0)dp[i][c] = min(dp[i][c], dp[j1][c - 1]);
dp[i][c] = min(dp[i][c], dp[j2][c] + 1);
}
}
return dp[n][p] <= q;
}
int main()
{
cin >> n >> p >> q;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
sort(arr + 1, arr + n + 1);
int l = 1, r = 1000000000;
while(l < r)
{
int mid = l + (r - l) / 2;
if (check(mid))
{
r = mid;
}
else
{
l = mid + 1;
}
//cout << l << " " << r << endl;
}
cout << r;
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门使用技巧:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
692 ms |
39652 KB |
Output is correct |
5 |
Correct |
1 ms |
876 KB |
Output is correct |
6 |
Correct |
699 ms |
39532 KB |
Output is correct |
7 |
Correct |
1 ms |
876 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
1 ms |
876 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
748 KB |
Output is correct |
14 |
Correct |
1 ms |
876 KB |
Output is correct |
15 |
Correct |
1 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
9836 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
255 ms |
21640 KB |
Output is correct |
4 |
Runtime error |
170 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |