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>
typedef long long ll;
using namespace std;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 2e3 + 100;
int a[N], n, p, q;
int f[N][N];
bool check(int w) {
mem(f, 0x3f);
f[0][0] = 0;
for (int i = 1; i <= n; i++) {
int l1 = lower_bound(a + 1, a + 1 + n, a[i] - w + 1) - a;
int l2 = lower_bound(a + 1, a + 1 + n, a[i] - 2 * w + 1) - a;
for (int j = 0; j <= n; j++) {
if (j) {
f[i][j] = min(f[i][j], f[l2 - 1][j - 1]);
}
f[i][j] = min(f[i][j], f[l1 - 1][j] + 1);
}
}
for (int i = 1; i <= q; i++) {
if (f[n][i] <= p)
return 1;
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> p >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
int l = 1, r = 1e9, m, ans;
while (l <= r) {
m = (l + r) / 2;
if (check(m)) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
watching.cpp: In function 'int main()':
watching.cpp:74:20: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
74 | cout << ans << '\n';
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |