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;
#define int long long
int a[2001], dp[2001][2001], posp[2001] , posq[2001], n , p , q;
int check(int w)
{
memset(dp , - 1, sizeof(dp));
for(int i = 0 ; i < n ; ++i)
{
posp[i] = upper_bound(a,a + n,a[i] + w - 1) - a;
posq[i] = upper_bound(a,a + n,a[i] + w * 2 - 1) - a;
}
dp[0][0] = 0;
for(int i = 0 ; i <= p ; ++i)
{
for(int j = 0 ; j <= q ; ++j)
{
if(dp[i][j] >= 0)
{
if(dp[i][j] >= n) return 1;
dp[i + 1][j] = max(dp[i + 1][j], posp[dp[i][j]]);
dp[i][j + 1] = max(dp[i][j + 1], posq[dp[i][j]]);
}
}
}
return 0;
}
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
//a
signed main(){
cin >> n >> p >> q;
for(int i = 0 ; i < n ; ++i)
cin >> a[i];
sort(a, a + n);
int l = 1, r = 1e9, mid = (l + r) / 2;
while(l != r)
{
if(check(mid) == 1) r = mid;
else l = mid + 1;
mid = (l + r) / 2;
}
cout << l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |