#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;
ll dp[n+5][n+5];
while(l<r){
ll w=(l+r)/2;
memset(dp,0,sizeof dp);
for(ll sum=0;sum<=p+q;sum++){
for(ll i=0;i<=sum;i++){
if(i<=p&&sum-i<=q){
ll j=sum-i;
if(i==0&&j==0){
dp[i][j]=0;
continue;
}
ll nxt=0;
if(i>0){
ll R=dp[i-1][j]+1;
R=lower_bound(a+1,a+n+1,a[dp[i-1][j]+1]+w)-a;
R--;
dp[i][j]=max(dp[i][j],R);
}
if(j>0){
ll R=dp[i][j-1]+1;
R=lower_bound(a+1,a+n+1,a[dp[i][j-1]+1]+2*w)-a;
R--;
dp[i][j]=max(dp[i][j],R);
}
}
}
}
if(dp[p][q]==n){
r=w;
}
else{
l=w+1;
}
}
cout<<l;
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:38:24: warning: unused variable 'nxt' [-Wunused-variable]
38 | ll nxt=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
31932 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
488 KB |
Output is correct |
7 |
Incorrect |
90 ms |
31836 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |