#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int n, p, q;
int a[N];
int dp[N][N];
int check(int val)
{
int i1 = 0, i2 = 0, i, j;
for (i = 0; i <= n; i++)
for (j = 0; j <= p; j++)
dp[i][j] = q + 1;
dp[0][0] = 0;
for (i = 1; i <= n; i++)
{
while (a[i1 + 1] + val <= a[i])
i1++;
while (a[i2 + 1] + val * 2 <= a[i])
i2++;
for (j = 0; j <= p; j++)
{
if (j)
dp[i][j] = min(dp[i][j], dp[i1][j - 1]);
dp[i][j] = min(dp[i][j], dp[i2][j] + 1);
}
}
for (i = 0; i <= p; i++)
if (dp[n][i] <= q)
return 1;
return 0;
}
int main()
{
int i, sol;
cin >> n >> p >> q;
p = min(p, n);
q = min(q, n);
for (i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
int st = 1, dr = 1e9;
while (st <= dr)
{
int mid = (st + dr) / 2;
if (check(mid))
{
sol = mid;
dr = mid - 1;
}
else
st = mid + 1;
}
cout << sol;
return 0;
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:54:13: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | cout << sol;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
2 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8364 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
228 ms |
16012 KB |
Output is correct |
4 |
Correct |
271 ms |
16004 KB |
Output is correct |
5 |
Correct |
23 ms |
8952 KB |
Output is correct |
6 |
Correct |
280 ms |
15948 KB |
Output is correct |
7 |
Correct |
9 ms |
8396 KB |
Output is correct |
8 |
Correct |
27 ms |
9272 KB |
Output is correct |
9 |
Correct |
124 ms |
14156 KB |
Output is correct |
10 |
Correct |
287 ms |
15948 KB |
Output is correct |
11 |
Correct |
22 ms |
9036 KB |
Output is correct |
12 |
Correct |
166 ms |
15996 KB |
Output is correct |
13 |
Correct |
9 ms |
8444 KB |
Output is correct |
14 |
Correct |
10 ms |
8484 KB |
Output is correct |
15 |
Correct |
10 ms |
8372 KB |
Output is correct |