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 ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, p, q;
cin >> n >> p >> q;
smin(p, n);
smin(q, n);
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
auto Can = [&] (int o) {
vector<int> x(n + 1), y(n + 1);
int j = 1;
for (int i = 1; i <= n; i++) {
while (a[i] - a[j] >= o) j++;
x[i] = j;
}
j = 1;
for (int i = 1; i <= n; i++) {
while (a[i] - a[j] >= 2 * o) j++;
y[i] = j;
}
vector<vector<int>> dp(n + 1, vector<int>(p + 1, 1e9));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= p; j++) {
if (j > 0) smin(dp[i][j], dp[x[i] - 1][j - 1]);
if (dp[y[i] - 1][j] != 1e9) smin(dp[i][j], dp[y[i] - 1][j] + 1);
}
}
for (int j = 0; j <= p; j++) if (dp[n][j] <= q) return true;
return false;
};
int l = 1; int r = 1e9;
int ans = 1e9;
while (l <= r) {
int mid = l + r >> 1;
if (Can(mid)) {
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << ans << en;
return 0;
}
Compilation message (stderr)
watching.cpp: In function 'int main()':
watching.cpp:49:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | int mid = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |