#include <iostream>
#include <algorithm>
using namespace std;
int n, p, q, a[2005], dp[2005][2005];
int searchLowerBound(int x) {
int l = 0, r = n - 1, m, ans = n;
while (l <= r) {
m = l + r >> 1;
if (a[m] >= x) {
r = m - 1;
ans = m;
}
else l = m + 1;
}
return ans;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> p >> q;
if (p + q >= n) {
cout << 1;
return 0;
}
for (int i = 0; i < n; i++) cin >> a[i];
int l = 1, r = 1e9, w, ans = -1;
sort(a, a + n);
while (l <= r) {
w = l + r >> 1;
for (int i = 0; i <= p; i++) for (int j = 0; j <= q; j++) dp[i][j] = 0;
for (int i = 0; i <= p; i++) for (int j = 0; j <= q; j++) {
if (dp[i][j] == n) {
ans = w;
r = w - 1;
goto end;
}
dp[i + 1][j] = max(dp[i + 1][j], searchLowerBound(a[dp[i][j]] + w));
dp[i][j + 1] = max(dp[i][j + 1], searchLowerBound(a[dp[i][j]] + 2 * w));
}
l = w + 1;
end:;
}
cout << ans;
return 0;
}
Compilation message
watching.cpp: In function 'int searchLowerBound(int)':
watching.cpp:10:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
10 | m = l + r >> 1;
| ~~^~~
watching.cpp: In function 'int main()':
watching.cpp:32:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | w = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
30 ms |
2652 KB |
Output is correct |
9 |
Correct |
42 ms |
6612 KB |
Output is correct |
10 |
Correct |
57 ms |
14940 KB |
Output is correct |
11 |
Correct |
62 ms |
2652 KB |
Output is correct |
12 |
Correct |
233 ms |
8852 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |