# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
306137 | quocnguyen1012 | Watching (JOI13_watching) | C++14 | 104 ms | 16120 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>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 2005;
int f[maxn][maxn];
int a[maxn], N;
int P, Q;
bool check(int len)
{
const int inf = 1e9;
fill_n(&f[0][0], maxn * maxn, inf);
f[0][0] = 0;
int l = 1, r = 1;
for (int i = 1; i <= N; ++i){
while (l <= N && a[l] <= a[i] - len) ++l;
while (r <= N && a[r] <= a[i] - 2 * len) ++r;
for (int j = 0; j <= P; ++j){
if (j > 0) f[i][j] = min(f[i][j], f[l - 1][j - 1]);
f[i][j] = min(f[i][j], f[r - 1][j] + 1);
}
}
return f[N][P] <= Q;
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> N >> P >> Q;
for (int i = 1; i <= N; ++i){
cin >> a[i];
}
sort(a + 1, a + 1 + N);
if (P + Q >= N) {
cout << 1;
return 0;
}
int l = 1, r = 1e9, mid;
while (l <= r){
mid = (l + r) / 2;
if (!check(mid)) l = mid + 1;
else r = mid - 1;
}
cout << l;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |