# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103655 | igba | Watching (JOI13_watching) | C++17 | 266 ms | 32432 KiB |
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>
using namespace std;
#define int long long
const int MAXN = 2020;
int n, p, q, a[MAXN], precalc[MAXN][2], dp[MAXN][MAXN];
bool ok(int w)
{
for(int i = 1, j = 1; i <= n; ++i, j = i)
{
while(a[j] - a[i] < w && j <= n)
j++;
precalc[i][0] = j;
while(a[j] - a[i] < 2 * w && j <= n)
j++;
precalc[i][1] = j;
}
precalc[n + 1][0] = precalc[n + 1][1] = n + 1;
memset(dp, 0, sizeof dp);
dp[1][0] = precalc[1][0], dp[0][1] = precalc[1][1];
for(int i = 1; i <= p; ++i)
for(int j = 1; j <= q; ++j)
dp[i][j] = max(precalc[dp[i - 1][j]][0], precalc[dp[i][j - 1]][1]);
return dp[p][q] > n;
}
signed main()
{
scanf("%lld %lld %lld", &n, &p, &q);
for(int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
if(p + q >= n)
printf("1\n"), exit(0);
sort(a + 1, a + n + 1);
int beg = 1, end = 1e9, mid;
while(beg <= end)
{
mid = (beg + end) >> 1;
if(ok(mid))
end = mid - 1;
else
beg = mid + 1;
}
printf("%lld\n", beg);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |