이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,p,q,l,r,md,ans,a[N],dp[N][N];
bool check(int w){
for (int i=1; i<=n; i++){
int l1=0, l2=0;
for (int j=0; j<=n; j++) dp[i][j]=1e9;
for (int j=i; j>=0; j--){
while(a[l1+1]<=a[i]-w) l1++;
while(a[l2+1]<=a[i]-2*w) l2++;
if(j > 0) dp[i][j]=dp[l1][j-1];
dp[i][j]=min(dp[i][j],dp[l2][j]+1);
}
}
for (int i=0; i<=p; i++) {
if(dp[n][i]<=q) return 1;
}
return 0;
}
int main() {
cin>>n>>p>>q;
p=min(p, n);
q=min(q, n);
for (int i=1; i<=n; i++)
cin>>a[i];
sort(a+1,a+n+1);
l=1; r=1e9;
while (l<=r){
md=(l+r)/2;
if (check(md)){
ans=md; r=md-1;
}
else l=md+1;
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |