#include <bits/stdc++.h>
using namespace std;
const int maxn = 2001;
int n, a[maxn], f[maxn][maxn], p, q, Next[maxn][2];
int bs(int x)
{
int l = 1;
int h = n;
while(l <= h)
{
int mid = l + h >> 1;
if(a[mid] < x) l = mid + 1;
else h = mid - 1;
}
return l;
}
bool Check(int gau)
{
for(int i = 1; i <= n; i++)
{
Next[i][0] = bs(a[i] + gau);
Next[i][1] = bs(a[i] + 2 * gau);
}
f[0][0] = 1;
for(int i = 0; i <= p; i++)
{
for(int j = 0; j <= q; j++)
{
if(i == 0 && j == 0) continue;
int x = 0;
if(i > 0)
{
x = max(x, Next[f[i - 1][j]][0]);
}
if(j > 0)
{
x = max(x, Next[f[i][j - 1]][1]);
}
if(x == n + 1) return true;
f[i][j] = x;
}
}
return false;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
cin >> n >> p >> q;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
sort(a + 1, a + n + 1);
if(p + q >= n) return cout << 1, 0;
int l = 1;
int h = 1e9;
while(l <= h)
{
int mid = (l + h) / 2;
if(Check(mid)) h = mid - 1;
else l = mid + 1;
}
cout << l;
}
Compilation message
watching.cpp: In function 'int bs(int)':
watching.cpp:15:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + h >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
436 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
464 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
664 KB |
Output is correct |
8 |
Correct |
3 ms |
744 KB |
Output is correct |
9 |
Correct |
2 ms |
892 KB |
Output is correct |
10 |
Correct |
3 ms |
892 KB |
Output is correct |
11 |
Correct |
3 ms |
972 KB |
Output is correct |
12 |
Correct |
4 ms |
972 KB |
Output is correct |
13 |
Correct |
2 ms |
972 KB |
Output is correct |
14 |
Correct |
2 ms |
972 KB |
Output is correct |
15 |
Correct |
3 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
972 KB |
Output is correct |
2 |
Correct |
2 ms |
972 KB |
Output is correct |
3 |
Correct |
3 ms |
972 KB |
Output is correct |
4 |
Correct |
3 ms |
972 KB |
Output is correct |
5 |
Correct |
3 ms |
972 KB |
Output is correct |
6 |
Correct |
3 ms |
972 KB |
Output is correct |
7 |
Correct |
6 ms |
972 KB |
Output is correct |
8 |
Correct |
17 ms |
1804 KB |
Output is correct |
9 |
Correct |
19 ms |
4256 KB |
Output is correct |
10 |
Correct |
28 ms |
9268 KB |
Output is correct |
11 |
Correct |
15 ms |
9268 KB |
Output is correct |
12 |
Correct |
70 ms |
9268 KB |
Output is correct |
13 |
Correct |
10 ms |
9268 KB |
Output is correct |
14 |
Correct |
10 ms |
9268 KB |
Output is correct |
15 |
Correct |
12 ms |
9268 KB |
Output is correct |