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;
int arr[2001] , dp[2001][2001] , x , n;
int solve(int idx , int r , int covered)
{ if(idx == n)
return 0 ;
int &ret = dp[idx][r] ;
if(covered > arr[idx])
return solve(idx+1 , r , covered);
if(ret != -1)
return ret ;
if(r >= n-idx)
return 0 ;
ret = solve(idx+1 , r , arr[idx] + x * 2) + 1 ;
if(r > 0)
ret = min(ret , solve(idx+1 , r-1 , arr[idx] + x));
return ret ;
}
int main()
{
int p , q;
cin>>n>>p>>q ;
if(p+q >= n)
return cout<<1 , 0 ;
for(int i = 0 ; i < n ; ++i)
cin>>arr[i] ;
sort(arr , arr + n);
int l = 1 , r = 1e9 , ans = 1e9 ;
while(l <= r)
{
memset(dp , -1 , sizeof(dp));
int mid = (l + r) >> 1 ;
x = mid ;
if(solve(0 , p , -1) <= q)
r = mid-1 , ans = min(ans , mid);
else
l = mid+1;
}
return cout<<ans , 0 ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |