This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
int n, p, q, a[2001];
bool possible(int w){
int dp[n+1][p+1];
for(int i=0; i<=n; ++i){
for(int j=0; j<=p; ++j){
dp[i][j] = i ? 1e10 : 0;
}
}
for(int i=1; i<=n; ++i){
for(int j=0; j<=p; ++j){
// use
if(j){
int f = upper_bound(a, a+n, max(0LL, a[i]-w)) - a - 1;
dp[i][j] = min(dp[i][j], dp[f][j-1]);
}
// don't
int f = upper_bound(a, a+n, max(0LL, a[i]-2*w)) - a - 1;
dp[i][j] = min(dp[i][j], dp[f][j] + 1);
}
}
return dp[n][p]<=q;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> p >> q;
a[0] = 0;
for(int i=1; i<=n; ++i) cin >> a[i];
sort(a+1, a+n+1);
if(p>n or q>n){
cout << 1 nl;
return 0;
}
int low = 0, high = 1e9;
while(low<high){
int mid = (low+high)/2;
if(possible(mid)) high = mid;
else low = mid+1;
}
cout << low nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |