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 <bits/stdc++.h>
using namespace std;
const int N = 2002;
int n, a, b;
int p[N], dp[N][N];
bool check(int w)
{
memset(dp, 0x3f, sizeof dp);
dp[0][0] = 0;
for(int i = 1; i <= n; i++)
{
int j1 = upper_bound(p + 1, p + n + 1, p[i] - w) - p - 1;
int j2 = upper_bound(p + 1, p + n + 1, p[i] - 2 * w) - p - 1;
for(int k = 0; k <= a; k++)
{
if(k) dp[i][k] = min(dp[i][k], dp[j1][k - 1]);
dp[i][k] = min(dp[i][k], dp[j2][k] + 1);
}
}
for(int i = 0; i <= a; i++)
if(dp[n][i] <= b) return 1;
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> a >> b;
for(int i = 1; i <= n; i++) cin >> p[i];
if(n <= a + b) return cout << 1, 0;
sort(p + 1, p + n + 1);
int l = 2, r = 1000000000, mid, ans = r;
while(l <= r)
{
mid = (l + r) >> 1;
if(check(mid))
{
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |