#include <bits/stdc++.h>
#define DIM 2010
#define INF 1000000000
using namespace std;
int v[DIM],dp[DIM][DIM];
int n,p,q,i;
int get_poz (int x){
int st = 1, dr = n, sol = 0;
while (st <= dr){
int mid = (st+dr)>>1;
if (v[mid] >= x){
sol = mid;
dr = mid-1;
} else st = mid+1;
}
return sol;
}
int verif (int val){
int poz = 1 , poz2 = 1;
for (int i=1;i<=n;i++){
while (v[i] - v[poz] + 1 > val)
poz++;
while (v[i] - v[poz2] + 1 > 2*val)
poz2++;
//int poz = get_poz (v[i] - val + 1);
//int poz2 = get_poz (v[i] - 2 * val + 1);
for (int j=0;j<=q;j++){
dp[i][j] = dp[poz-1][j] + 1;
if (j)
dp[i][j] = min (dp[i][j],dp[poz2-1][j-1]);
}
}
if (dp[n][q] <= p)
return 1;
return 0;
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>p>>q;
for (i=1;i<=n;i++)
cin>>v[i];
sort (v+1,v+n+1);
p = min (p,n), q = min (q,n);
int st = 1, dr = INF, sol = 0;
while (st <= dr){
int mid = (st+dr)>>1;
if (verif(mid)){
sol = mid;
dr = mid-1;
} else st = mid+1;
}
cout<<sol;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 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 |
688 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 |
5 ms |
8268 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
128 ms |
16052 KB |
Output is correct |
4 |
Correct |
12 ms |
8908 KB |
Output is correct |
5 |
Correct |
154 ms |
15948 KB |
Output is correct |
6 |
Correct |
153 ms |
15948 KB |
Output is correct |
7 |
Correct |
6 ms |
8396 KB |
Output is correct |
8 |
Correct |
78 ms |
14220 KB |
Output is correct |
9 |
Correct |
17 ms |
9316 KB |
Output is correct |
10 |
Correct |
14 ms |
9036 KB |
Output is correct |
11 |
Correct |
156 ms |
15948 KB |
Output is correct |
12 |
Correct |
94 ms |
16104 KB |
Output is correct |
13 |
Correct |
7 ms |
8396 KB |
Output is correct |
14 |
Correct |
6 ms |
8380 KB |
Output is correct |
15 |
Correct |
7 ms |
8480 KB |
Output is correct |