#include <bits/stdc++.h>
using namespace std;
int find(int x, vector<int> &Tab, int L, int R)
{
int m = (L + R) / 2;
if (R == L)
return m;
if (Tab[m] > x)
return find(x, Tab, L, m);
else
return find(x, Tab, m + 1, R);
}
int main()
{
int N, P, Q;
cin >> N >> P >> Q;
P = min(N, P);
Q = min(N, Q);
vector<int> Tab(N);
for (int i = 0; i < N; i++)
{
cin >> Tab[i];
}
sort(Tab.begin(), Tab.end());
int L = 1, R = 1000000000;
for (int dico = 0; dico < 30; dico++)
{
int m = (L + R) / 2;
vector<int> small(N), big(N);
for (int i = 0; i < N; i++)
{
small[i] = find(Tab[i] + m - 1, Tab, 0, N);
big[i] = find(Tab[i] + 2 * m - 1, Tab, 0, N);
}
vector<vector<int>> dp(N + 1, vector<int>(P + 1, -1));
dp[0][0] = Q;
for (int i = 0; i < N; i++)
{
for (int j = 0; j <= P; j++)
{
if (j != P)
dp[small[i]][j + 1] = max(dp[i][j], dp[small[i]][j + 1]);
if (dp[i][j] != 0)
dp[big[i]][j] = max(dp[i][j] - 1, dp[big[i]][j]);
}
}
bool b = 0;
for (int i = 0; i <= P; i++)
{
if (dp[N][i] >= 0)
b = 1;
}
if (b)
R = m;
else
L = m + 1;
}
cout << L;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
428 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
392 ms |
12320 KB |
Output is correct |
4 |
Correct |
542 ms |
16492 KB |
Output is correct |
5 |
Correct |
24 ms |
1228 KB |
Output is correct |
6 |
Correct |
524 ms |
16328 KB |
Output is correct |
7 |
Correct |
8 ms |
604 KB |
Output is correct |
8 |
Correct |
34 ms |
1516 KB |
Output is correct |
9 |
Correct |
182 ms |
6572 KB |
Output is correct |
10 |
Correct |
522 ms |
15668 KB |
Output is correct |
11 |
Correct |
26 ms |
1276 KB |
Output is correct |
12 |
Correct |
242 ms |
8244 KB |
Output is correct |
13 |
Correct |
10 ms |
600 KB |
Output is correct |
14 |
Correct |
15 ms |
604 KB |
Output is correct |
15 |
Correct |
11 ms |
604 KB |
Output is correct |