이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define int long long
const int N = 2005, inf=1e18;
int n, p, q, a[N], dp[N][N],l1,l2;
set <pair <int, int> > s;
int ans;
bool check(int mid){
for(int i=1; i<=n; i++){
set <pair <int, int> > :: iterator it = s.lower_bound({a[i]-mid+1, 0});
l1 = (*it).ss-1;
it = s.lower_bound({a[i]-2*mid+1, 0});
l2 = (*it).ss-1;
for (int x=0; x<=n; x++) {
dp[i][x]=1e9;
if(x==0){
dp[i][x]=dp[l2][x]+1;
}
else{
dp[i][x]=min(dp[l1][x-1], dp[l2][x]+1);
}
if (i==n && x<=p && dp[i][x]<=q) return 1;
}
}
return 0;
}
signed main() {
cin >> n >> p >> q;
for(int i=1; i<=n; i++){
cin >> a[i];
}
sort(a+1, a+n+1);
for (int i=1; i<=n; i++) {
s.insert({a[i], i});
}
int l=1, r=1e9;
while(l<=r){
int mid=(l+r)/2;
if(check(mid)){
ans=mid;
r=mid-1;
} else l=mid+1;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |