이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, p, q;
cin >> n >> p >> q;
if(p + q >= n) {
cout <<"1\n";
return 0;
}
vector<int> a(n);
for(int&A:a) cin >> A;
sort(a.begin(), a.end());
int lo = 1, hi = 1e9;
while(lo <= hi){
int mid = (lo + hi) / 2;
vector<vector<int>> dp(n + 1, vector<int>(n + 1, -1));
vector<int> P(n + 1), Q(n + 1);
for(int i=0; i < n; i++){
P[i] = (lower_bound(a.begin(), a.end(), a[i] + mid) - a.begin()) - i;
}
for(int i=0; i < n; i++){
Q[i] = (lower_bound(a.begin(), a.end(), a[i] + mid * 2) - a.begin()) - i;
}
dp[0][0] = 0;
bool g = 0;
for(int i=0; i <= p; i++){
for(int j=0; j <= q; j++){
if(dp[i][j] == n){
g = 1;
}
if(dp[i][j] != -1){
dp[i + 1][j] = max(dp[i+1][j], P[dp[i][j]] + dp[i][j]);
dp[i][j + 1] = max(dp[i][j + 1], Q[dp[i][j]] + dp[i][j]);
}
}
}
g?hi=mid-1:lo=mid+1;
}
cout << lo << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |