#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
int N, P, Q, A[2005], dp[2005][2005];
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> P >> Q;
P = min(N, P);
Q = min(N, Q);
for (int i = 1; i <= N; i++) cin >> A[i];
sort(A + 1, A + 1 + N);
int lo = 1, hi = A[N] - A[1], ans = -1;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
for (int i = 1, tmp = 0, tmp2 = 0; i <= N; i++) {
while (A[tmp + 1] <= A[i] - mid) tmp++;
while (A[tmp2 + 1] <= A[i] - 2 * mid) tmp2++;
for (int j = 0; j <= P; j++)
dp[i][j] = min(j ? dp[tmp][j - 1] : LLONG_MAX, dp[tmp2][j] + 1);
}
if (dp[N][P] <= Q) ans = mid, hi = mid - 1;
else lo = mid + 1;
}
cout << ans << '\n';
}
Compilation message
watching.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8404 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
120 ms |
31724 KB |
Output is correct |
4 |
Correct |
173 ms |
31744 KB |
Output is correct |
5 |
Correct |
15 ms |
9556 KB |
Output is correct |
6 |
Correct |
153 ms |
31744 KB |
Output is correct |
7 |
Correct |
6 ms |
8532 KB |
Output is correct |
8 |
Correct |
13 ms |
10332 KB |
Output is correct |
9 |
Correct |
72 ms |
20180 KB |
Output is correct |
10 |
Correct |
155 ms |
31748 KB |
Output is correct |
11 |
Correct |
17 ms |
9808 KB |
Output is correct |
12 |
Correct |
93 ms |
23728 KB |
Output is correct |
13 |
Correct |
5 ms |
8532 KB |
Output is correct |
14 |
Correct |
6 ms |
8668 KB |
Output is correct |
15 |
Correct |
6 ms |
8668 KB |
Output is correct |