#include <bits/stdc++.h>
#define MAX_N 2000
using namespace std;
int rez;
int n, p, q;
int a[MAX_N + 1 + 1];
int dp[MAX_N + 1][MAX_N + 1];
void readFile()
{
cin >> n >> p >> q;
for(int i = 1; i <= n; i ++)
cin >> a[i];
}
void init0()
{
for(int i = 1; i <= n; i ++)
{
for(int j = 0; j <= n; j ++)
dp[i][j] = -1;
}
}
bool pos(int nr)
{
init0();
dp[1][q] = p;
int dr[2] = {1, 1};
int lim[2] = {nr, nr << 1};
for(int i = 1; i <= n; i ++)
{
for(int h = 0; h <= 1; h ++)
{
while(dr[h] + 1 <= n && a[dr[h] + 1] - a[i] < lim[h])
dr[h] ++;
dr[h] ++;
}
for(int j = 0; j <= n; j ++)
{
if(dp[i][j] != -1)
{
if(j > 0 && dr[1] > n)
return 1;
if(dr[0] > n && dp[i][j] > 0)
return 1;
if(j > 0)
dp[dr[1]][j - 1] = max(dp[dr[1]][j - 1], dp[i][j]);
if(dp[i][j] > 0)
dp[dr[0]][j] = max(dp[dr[0]][j], dp[i][j] - 1);
}
}
dr[0] --;
dr[1] --;
}
return 0;
}
int cautBin()
{
int i = 0;
int pas = 1 << 29;
while(pas != 0)
{
if(pos(i + pas) == 0)
i += pas;
pas >>= 1;
}
return i + 1;
}
void solve()
{
if(p + q >= n)
{
rez = 1;
return;
}
sort(a + 1, a + n + 1);
rez = cautBin();
}
void printFile()
{
cout << rez << "\n";
}
int main()
{
readFile();
solve();
printFile();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
6 ms |
768 KB |
Output is correct |
10 |
Correct |
6 ms |
768 KB |
Output is correct |
11 |
Correct |
5 ms |
768 KB |
Output is correct |
12 |
Correct |
6 ms |
768 KB |
Output is correct |
13 |
Correct |
6 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
768 KB |
Output is correct |
15 |
Correct |
6 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
16128 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
190 ms |
16000 KB |
Output is correct |
8 |
Correct |
189 ms |
16000 KB |
Output is correct |
9 |
Correct |
190 ms |
16000 KB |
Output is correct |
10 |
Correct |
184 ms |
16000 KB |
Output is correct |
11 |
Correct |
181 ms |
16000 KB |
Output is correct |
12 |
Correct |
200 ms |
16000 KB |
Output is correct |
13 |
Correct |
164 ms |
16120 KB |
Output is correct |
14 |
Correct |
161 ms |
16000 KB |
Output is correct |
15 |
Correct |
185 ms |
16000 KB |
Output is correct |