This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |