#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){
if(dp[i-1][j]==n){
dp[i][j]=n;
continue;
}
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){
if(dp[i][j-1]==n){
dp[i][j]=n;
continue;
}
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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
352 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
0 ms |
532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
31836 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
100 ms |
31740 KB |
Output is correct |
8 |
Correct |
173 ms |
31936 KB |
Output is correct |
9 |
Correct |
193 ms |
31932 KB |
Output is correct |
10 |
Correct |
257 ms |
31936 KB |
Output is correct |
11 |
Correct |
218 ms |
31804 KB |
Output is correct |
12 |
Correct |
625 ms |
31928 KB |
Output is correct |
13 |
Correct |
101 ms |
31836 KB |
Output is correct |
14 |
Correct |
98 ms |
31936 KB |
Output is correct |
15 |
Correct |
97 ms |
31836 KB |
Output is correct |