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;
const int N = 2005;
int n, p, q, a[N], dp[N][N];
int ok(int w) {
memset(dp, 63, sizeof dp);
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
auto ip = max(0l, upper_bound(a, a+i, a[i] - w) - a - 1);
auto iq = max(0l, upper_bound(a, a+i, a[i] - 2*w) - a - 1);
for (int j = 0; j <= p; ++j) {
if (j) {
dp[i][j] = min(dp[i][j], dp[ip][j-1]);
}
dp[i][j] = min(dp[i][j], dp[iq][j] + 1);
}
}
for (int j = 0; j <= p; ++j)
if (dp[n][j] <= q) return 1;
return 0;
}
int main() {
scanf("%d%d%d", &n, &p, &q);
p = min(p, n); q = min(q, n);
for (int i = 1; i <= n; ++i) scanf("%d", a+i);
sort(a+1, a+n+1);
int l = 0, r = 1e9+2;
while (r - l > 1) {
auto m = (l+r)/2;
if (ok(m)) r = m;
else l = m;
}
printf("%d", r);
return 0;
}
Compilation message (stderr)
watching.cpp: In function 'int main()':
watching.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d%d%d", &n, &p, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:29:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | for (int i = 1; i <= n; ++i) scanf("%d", a+i);
| ~~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |