#include <bits/stdc++.h>
#define DEBUG false
using namespace std;
const int N = 2e3+10;
int n,P,Q,dp[N][N];
main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> P >> Q;
vector<int> a(n+1, 0);
for(int i=1; i<=n; i++){
cin >> a[i];
}
sort(a.begin(), a.end());
if(P+Q >= n){
cout << "1\n";
return 0;
}
int l = 1, r = 1e9, ans = -1, lim = min(P, Q), chk = max(P, Q);
int code = (P < Q);
while(l <= r){
int mid = (l+r)/2;
for(int i=1, j1, j2; i<=n; i++){
if(code == 0){
j1 = lower_bound(a.begin()+1, a.end(), a[i]-2*mid+1)-a.begin();
j2 = lower_bound(a.begin()+1, a.end(), a[i]-mid+1)-a.begin();
}else{
j1 = lower_bound(a.begin()+1, a.end(), a[i]-mid+1)-a.begin();
j2 = lower_bound(a.begin()+1, a.end(), a[i]-2*mid+1)-a.begin();
}
for(int q=0; q<=lim; q++){
dp[i][q] = 1e9;
if(q > 0)
dp[i][q] = dp[j1-1][q-1];
dp[i][q] = min(dp[i][q], dp[j2-1][q]+1);
}
}
if(dp[n][lim] <= chk){
ans = mid;
r = mid-1;
}else{
l = mid+1;
}
}
cout << ans << "\n";
}
Compilation message
watching.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8364 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
9 ms |
8460 KB |
Output is correct |
8 |
Correct |
21 ms |
9292 KB |
Output is correct |
9 |
Correct |
22 ms |
9320 KB |
Output is correct |
10 |
Correct |
22 ms |
9040 KB |
Output is correct |
11 |
Correct |
18 ms |
9044 KB |
Output is correct |
12 |
Correct |
123 ms |
15992 KB |
Output is correct |
13 |
Correct |
9 ms |
8396 KB |
Output is correct |
14 |
Correct |
10 ms |
8464 KB |
Output is correct |
15 |
Correct |
11 ms |
8396 KB |
Output is correct |