#include <bits/stdc++.h>
using namespace std;
#define ar array
#define int long long
#define ld long double
#define crash assert(69 == 420)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 3000;
const int K = 300;
const int LOG = 30;
int n, p, q;
int A[N];
int dp[N][N];
bool check(int x){
for(int i = 1;i <= n;i++){
for(int j = 0;j <= p;j++){
dp[i][j] = INF;
}
}
for(int i = 1;i <= n;i++){
int l = upper_bound(A + 1,A + n + 1, A[i] - x) - A;
int r = upper_bound(A + 1, A + n + 1, A[i] - 2 * x) - A;
for(int j = 0;j <= p;j++){
if(j)dp[i][j] = min(dp[i][j], dp[l - 1][j - 1]);
dp[i][j] = min(dp[i][j], dp[r - 1][j] + 1);
}
}
for(int i = 0;i <= p;i++){
if(dp[n][i] <= q)return 1;
}
return 0;
}
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
cin>>n>>p>>q;
for(int i =1 ;i <= n;i++)cin>>A[i];
sort(A + 1, A + n + 1);
if(p + q >= n){
cout<<1;
return 0;
}
int ans = (1 << LOG) - 1;
int tm = 1 << (LOG - 1);
for(int i =0;i < LOG;i++){
if(check(tm)){
ans = tm;
tm -= (tm & -tm) >> 1;
}else tm += (tm & -tm)>>1;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
47708 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
47708 KB |
Output is correct |
8 |
Correct |
18 ms |
47736 KB |
Output is correct |
9 |
Correct |
73 ms |
47708 KB |
Output is correct |
10 |
Correct |
181 ms |
47708 KB |
Output is correct |
11 |
Correct |
15 ms |
47708 KB |
Output is correct |
12 |
Correct |
89 ms |
47760 KB |
Output is correct |
13 |
Correct |
8 ms |
47708 KB |
Output is correct |
14 |
Correct |
9 ms |
47724 KB |
Output is correct |
15 |
Correct |
9 ms |
47708 KB |
Output is correct |