#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, P, Q;
ll A[2005];
ll B[2005][2];
ll D[2005][2005];
ll f(ll W){
for(int i = 1; i <= N; i++){
B[i][0] = upper_bound(A, A + i, A[i] - W) - A - 1;
B[i][1] = upper_bound(A, A + i, A[i] - 2 * W) - A - 1;
}
for(int i = 1; i <= N; i++){
for(int j = 0; j <= N; j++){
D[i][j] = D[B[i][1]][j] + 1;
if(j >= 1) D[i][j] = min(D[i][j], D[B[i][0]][j - 1]);
}
}
return D[N][min(P, N)];
}
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N >> P >> Q;
A[0] = -1e15;
for(int i = 1; i <= N; i++){
cin >> A[i];
}
sort(A + 1, A + N + 1);
ll L = 1, R = 1e9;
while(L <= R){
ll m = (L + R) / 2;
if(f(m) <= Q) R = m - 1;
else L = m + 1;
}
cout << L;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
708 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
31672 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
169 ms |
31764 KB |
Output is correct |
4 |
Correct |
182 ms |
31764 KB |
Output is correct |
5 |
Correct |
198 ms |
31764 KB |
Output is correct |
6 |
Correct |
169 ms |
31692 KB |
Output is correct |
7 |
Correct |
180 ms |
31692 KB |
Output is correct |
8 |
Correct |
190 ms |
31780 KB |
Output is correct |
9 |
Correct |
172 ms |
31768 KB |
Output is correct |
10 |
Correct |
178 ms |
31820 KB |
Output is correct |
11 |
Correct |
219 ms |
31764 KB |
Output is correct |
12 |
Correct |
183 ms |
31764 KB |
Output is correct |
13 |
Correct |
183 ms |
31764 KB |
Output is correct |
14 |
Correct |
237 ms |
31764 KB |
Output is correct |
15 |
Correct |
201 ms |
31812 KB |
Output is correct |