#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
#define ff first
#define ss second
const ll mod = 1000000007;
void solve(){
ll n,p,q; cin>>n>>p>>q;
ll a[n+1];
forp(i,1,n){
cin>>a[i];
}
if(p+q>=n){
cout<<1<<newl; return;
}
sort(a+1,a+n+1);
a[0]=0;
ll w1=1,w2=a[n]-a[1];
ll w,i1,i2;
while(w1<w2){
w=(w1+w2)/2;
ll dp[p+1][q+1];
memset(dp,0,sizeof(dp));
bool g=0;
forp(i,0,p){
if(g){break;}
forp(j,0,q){
i1=i2=0;
if(j){
//cout<<dp[i][j-1]<<newl;
i1 = upper_bound(a+1,a+n+1,a[dp[i][j-1]+1]+2*w-1)-a; i1--; //cout<<i1<<" ";
}
if(i){
//cout<<dp[i-1][j]<<newl;
i2 = upper_bound(a+1,a+n+1,a[dp[i-1][j]+1]+w-1)-a; i2--; //cout<<i2<<newl;
}
dp[i][j]=max(i1,i2);
if(dp[i][j]==n){
g=1; break;
}
}
}
if(g||dp[p][q]==n){
w2=w;
} else {
w1=w+1;
}
}
cout<<w1<<newl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1; //cin>>t;
while(t--)solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
104 ms |
1056 KB |
Output is correct |
9 |
Correct |
92 ms |
1060 KB |
Output is correct |
10 |
Correct |
124 ms |
1652 KB |
Output is correct |
11 |
Correct |
74 ms |
1600 KB |
Output is correct |
12 |
Correct |
810 ms |
7860 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |