#include <bits/stdc++.h>
using namespace std;
int N, P, Q;
int a[100000];
int dp[2001][2001]; // [num of events][large cameras]
int jmps[2001], jmpl[2001];
bool works(int mid){
fill(dp[0], dp[N]+Q+1, 1e9);
fill(dp[0], dp[0]+Q+1, 0);
iota(jmps, jmps+N+1, -1);
iota(jmpl, jmpl+N+1, -1);
for(int i = N-1; i >= 0; i--){
int idxs = upper_bound(a, a+N, a[i]-mid) - a - 1;
int idxl = upper_bound(a, a+N, a[i]-2*mid) - a - 1;
jmps[i] = idxs;
jmpl[i] = idxl;
}
for(int i = 1; i <= N; i++){
int pvs = jmps[i-1]+1, pvl = jmpl[i-1]+1;
dp[i][0] = dp[pvs][0] + 1;
for(int j = 1; j <= Q; j++){
dp[i][j] = min(dp[pvl][j-1], dp[pvs][j] + 1);
}
}
return (dp[N][Q] <= P);
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> P >> Q;
if(P+Q >= N){
cout << 1 << endl;
return 0;
}
for(int i = 0; i < N; i++){
cin >> a[i];
}
sort(a, a+N);
int lo = 0, hi = 1e9, mid = 0;
while(lo < hi){
mid = (lo + hi) / 2;
if(works(mid)){
hi = mid-1;
}else{
lo = mid+1;
}
}
while(works(mid)) mid--;
while(!works(mid)) mid++;
cout << mid << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1132 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
4 ms |
1132 KB |
Output is correct |
8 |
Correct |
6 ms |
1132 KB |
Output is correct |
9 |
Correct |
4 ms |
1132 KB |
Output is correct |
10 |
Correct |
4 ms |
1132 KB |
Output is correct |
11 |
Correct |
4 ms |
1132 KB |
Output is correct |
12 |
Correct |
4 ms |
1132 KB |
Output is correct |
13 |
Correct |
4 ms |
1132 KB |
Output is correct |
14 |
Correct |
6 ms |
1132 KB |
Output is correct |
15 |
Correct |
5 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
15980 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
101 ms |
16000 KB |
Output is correct |
8 |
Correct |
166 ms |
15980 KB |
Output is correct |
9 |
Correct |
120 ms |
16108 KB |
Output is correct |
10 |
Correct |
115 ms |
15980 KB |
Output is correct |
11 |
Correct |
249 ms |
15980 KB |
Output is correct |
12 |
Correct |
183 ms |
16108 KB |
Output is correct |
13 |
Correct |
118 ms |
15980 KB |
Output is correct |
14 |
Correct |
104 ms |
15980 KB |
Output is correct |
15 |
Correct |
106 ms |
15980 KB |
Output is correct |