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+1);
for(int i = 1;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));
bool good = false;
for(int i = 0;i<=P;++i){
for(int j = 0;j<=Q;++j){
if(i >= 1){
int it = upper_bound(arr.begin(),arr.end(),arr[dp[i-1][j]+1]+w-1)-arr.begin()-1;
dp[i][j] = max(dp[i][j],it);
}
if(j >= 1){
int it2 = upper_bound(arr.begin(),arr.end(),arr[dp[i][j-1]+1]+2*w-1)-arr.begin()-1;
dp[i][j] = max(dp[i][j],it2);
}
if(dp[i][j] >= N){
good = true;
}
}
}
if(good){
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... |