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 main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N,P,Q; cin >> N >> P >> Q;
vector<int> arr(N);
for(int i = 0;i<N;++i) cin >> arr[i];
if(P+Q >= N){
cout << 1 << "\n";
return 0;
}
sort(arr.begin(),arr.end());
int lo = 0, hi = 1e9;
while(lo < hi){
int w = lo+(hi-lo)/2;
vector<vector<int>> dp(P+1,vector<int>(Q+1,0));
for(int i = 0;i<=P;++i){
for(int j = 0;j<=Q;++j){
int ind = dp[i][j];
if(i < P){
int it = lower_bound(arr.begin(),arr.end(),arr[ind]+w)-arr.begin();
dp[i+1][j] = max(dp[i+1][j],it);
}
if(j < Q){
int it2 = lower_bound(arr.begin(),arr.end(),arr[ind]+2*w)-arr.begin();
dp[i][j+1] = max(dp[i][j+1],it2);
}
}
}
if(dp[P][Q] >= N){
hi = w;
}
else{
lo = w+1;
}
}
cout << lo << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |