이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,p,q;
cin>>n>>p>>q;
ll a[n+5];
for(ll i=1;i<=n;i++){
cin>>a[i];
}
if(p+q>=n){
cout<<1;
return 0;
}
sort(a+1,a+n+1);
ll l=1,r=1e9;
bool dp[n+5][n+5][n+5];
while(l<r){
ll w=(l+r)/2;
memset(dp,0,sizeof dp);
for(ll i=n;i>=1;i--){
for(ll j=p;j>=0;j--){
for(ll k=q;k>=0;k--){
if(j==0&&k==0){
continue;
}
if(k>0){
ll R=i;
while(R<n&&a[R+1]<a[i]+2*w){
R++;
}
if(R==n){
dp[i][j][k]=true;
continue;
}
dp[i][j][k]|=dp[R+1][j][k-1];
}
if(j>0){
ll R=i;
while(R<n&&a[R+1]<a[i]+w){
R++;
}
if(R==n){
dp[i][j][k]=true;
continue;
}
dp[i][j][k]|=dp[R+1][j-1][k];
}
}
}
}
if(dp[1][p][q]){
r=w;
}
else{
l=w+1;
}
}
cout<<l;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |