#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1372 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
1372 KB |
Output is correct |
8 |
Correct |
4 ms |
1372 KB |
Output is correct |
9 |
Correct |
4 ms |
1372 KB |
Output is correct |
10 |
Correct |
23 ms |
1372 KB |
Output is correct |
11 |
Correct |
26 ms |
1372 KB |
Output is correct |
12 |
Correct |
60 ms |
1372 KB |
Output is correct |
13 |
Correct |
4 ms |
1372 KB |
Output is correct |
14 |
Correct |
3 ms |
1372 KB |
Output is correct |
15 |
Correct |
4 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
145 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |