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 ll long long
const int N = 2e3 + 5;
const int mod = 1e9 + 7;
int n, P, Q;
int a[N];
int dp[N][N];
bool check(int w) {
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for(int i = 1; i <= n; ++i) {
int kp = lower_bound(a + 1, a + n + 1, a[i] + w) - a - 1;
int kq = lower_bound(a + 1, a + n + 1, a[i] + 2 * w) - a - 1;
for(int j = 0; j <= P; ++j) {
dp[kp][j + 1] = min(dp[kp][j + 1], dp[i - 1][j]);
dp[kq][j] = min(dp[kq][j], dp[i - 1][j] + 1);
}
}
for(int i = 0; i <= P; ++i) if(dp[n][i] <= Q) return true;
return false;
}
void solve() {
cin >> n >> P >> Q;
for(int i = 1; i <= n; ++i) cin >> a[i];
if(n <= P + Q) {
cout << 1 << '\n';
return;
}
sort(a + 1, a + n + 1);
int l = 1, r = (int)1e9, ans = -1;
while(l <= r) {
int m = l + r >> 1;
if(check(m)) ans = m, r = m - 1;
else l = m + 1;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) solve();
return 0;
}
Compilation message (stderr)
watching.cpp: In function 'void solve()':
watching.cpp:36:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int m = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |