This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |