#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 2000;
int const inf = 1000000000;
int v[1 + nmax];
int n, p, q;
int dp[1 + nmax][1 + nmax];
int test(int target){
for(int i = 0; i <= n; i++)
for(int j = 0; j <= p; j++)
dp[i][j] = n + 1;
dp[0][0] = 0;
for(int i = 1;i <= n; i++) {
int p1 = i, p2 = i;
while(1 <= p1 && v[i] - v[p1] + 1 <= target)
p1--;
while(1 <= p2 && v[i] - v[p2] + 1 <= 2 * target)
p2--;
for(int j = 1; j <= p; j++)
dp[i][j] = min(dp[i][j], dp[p1][j - 1]);
for(int j = 0; j <= p; j++)
dp[i][j] = min(dp[i][j], dp[p2][j] + 1);
}
for(int i = 0;i <= p; i++)
if(dp[n][i] <= q)
return 1;
return 0;
}
int binarysearch(int from, int to){
if(from < to){
int mid = (from + to) / 2;
if(test(mid) == 1)
return binarysearch(from, mid);
else
return binarysearch(mid + 1, to);
} else
return from;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> p >> q;
p = min(n, p);
q = min(n, q);
for(int i = 1; i <= n; i++)
cin >> v[i];
sort(v + 1, v + n + 1);
cout << binarysearch(1, inf);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
6 ms |
768 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
5 ms |
768 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
768 KB |
Output is correct |
15 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
8448 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
282 ms |
16120 KB |
Output is correct |
4 |
Correct |
330 ms |
16120 KB |
Output is correct |
5 |
Correct |
36 ms |
8960 KB |
Output is correct |
6 |
Correct |
336 ms |
16000 KB |
Output is correct |
7 |
Correct |
36 ms |
8448 KB |
Output is correct |
8 |
Correct |
42 ms |
9344 KB |
Output is correct |
9 |
Correct |
154 ms |
14336 KB |
Output is correct |
10 |
Correct |
320 ms |
16000 KB |
Output is correct |
11 |
Correct |
35 ms |
9088 KB |
Output is correct |
12 |
Correct |
195 ms |
16184 KB |
Output is correct |
13 |
Correct |
41 ms |
8448 KB |
Output is correct |
14 |
Correct |
34 ms |
8576 KB |
Output is correct |
15 |
Correct |
30 ms |
8576 KB |
Output is correct |