#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
void solve() {
int n,p,q;
cin>>n>>p>>q;
int a[n+1];
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1);
p=min(p,n);
q=min(q,n);
int l=1,r=1e9;
while(l<r){
int m=(l+r)/2;
int dp[n+1][q+1];
for(int i=0;i<=q;i++)dp[0][i]=0;
int idx1=1,idx2=1;
for(int i=1;i<=n;i++){
while(a[i]-a[idx1]+1>m)idx1++;
while(a[i]-a[idx2]+1>2*m)idx2++;
for(int j=0;j<=q;j++){
dp[i][j]=dp[idx1-1][j]+1;
if(j){
dp[i][j]=min(dp[i][j],dp[idx2-1][j-1]);
}
}
}
if(dp[n][q]<=p)r=m;
else l=m+1;
}
cout<<l;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
388 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
155 ms |
12120 KB |
Output is correct |
4 |
Correct |
6 ms |
856 KB |
Output is correct |
5 |
Correct |
97 ms |
16132 KB |
Output is correct |
6 |
Correct |
98 ms |
16096 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
36 ms |
6236 KB |
Output is correct |
9 |
Correct |
7 ms |
1372 KB |
Output is correct |
10 |
Correct |
6 ms |
1116 KB |
Output is correct |
11 |
Correct |
94 ms |
15192 KB |
Output is correct |
12 |
Correct |
48 ms |
8136 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |