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;
int N, P, Q;
int a[2222];
int big[2222];
int tiny[2222];
int search(int b, int e, int val) {
if(b == e) {
return b;
}
int m = (b + e) >> 1;
if(val < a[m]) return search(b, m, val);
else return search(m + 1, e, val);
}
const int inf = 1e8;
int dp[2222][2222];
bool good(int w) {
for(int i = 1; i <= N; i++) {
tiny[i] = search(1, N, a[i] - w) - 1;
big[i] = search(1, N, a[i] - w - w) - 1;
}
for(int i = 1; i <= N; i++) {
for(int j = 0; j <= P; j++) {
dp[i][j] = inf;
if(j) dp[i][j] = min(dp[i][j], dp[tiny[i]][j - 1]);
dp[i][j] = min(dp[i][j], dp[big[i]][j] + 1);
}
}
return (dp[N][P] <= Q);
}
int find(int b, int e) {
if(b == e) {
return b;
}
int m = (b + e) >> 1;
if(good(m)) return find(b, m);
else return find(m + 1, e);
}
int main() {
scanf("%d %d %d", &N, &P, &Q);
for(int i = 1; i <= N; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + N + 1);
if(N <= P || N <= Q) {
printf("%d\n", 1);
exit(0);
}
printf("%d\n", find(1, 1000000000));
return 0;
}
Compilation message (stderr)
watching.cpp: In function 'int main()':
watching.cpp:46:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &N, &P, &Q);
^
watching.cpp:48:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |