#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define watch(x) cout << (#x) << " : " << x << '\n'
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int N = 2222;
const int INF = 2e9 + 128;
int dp[N][N];
int a[N];
void solve() {
int n, p, q;
cin >> n >> p >> q;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
if (p + q >= n) {
cout << 1 << '\n';
return;
}
auto check = [&](int w) -> bool {
for (int i = 0; i <= n+2; i++)
for (int c = 0; c <= p+2; c++)
dp[i][c] = INF;
for (int i = 0; i <= p; i++)
dp[0][i] = 0;
int j0 = 0, j1 = 0;
for (int i = 1; i <= n; i++) {
// place w.
while (j0 + 1 <= n && a[j0 + 1] - a[i] + 1 <= w)
j0++;
while (j1 + 1 <= n && a[j1 + 1] - a[i] + 1 <= 2*w)
j1++;
for (int lp = 0; lp <= p; lp++)
dp[j0][lp] = min(dp[j0][lp], dp[i-1][lp+1]);
for (int lp = 0; lp <= p; lp++)
dp[j1][lp] = min(dp[j1][lp], dp[i-1][lp]+1);
}
for (int i = 0; i <= p; i++)
if (dp[n][i] <= q)
return true;
return false;
};
int l = 0, r = 1e9 + 128;
while (l + 1 < r) {
int m = (l + r) >> 1;
if (check(m))
r = m;
else
l = m;
}
cout << r << '\n';
}
main() {
boost;
solve();
return 0;
}
Compilation message
watching.cpp:71:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
71 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
19032 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
19036 KB |
Output is correct |
8 |
Correct |
21 ms |
19036 KB |
Output is correct |
9 |
Correct |
113 ms |
19036 KB |
Output is correct |
10 |
Correct |
289 ms |
19036 KB |
Output is correct |
11 |
Correct |
16 ms |
19036 KB |
Output is correct |
12 |
Correct |
180 ms |
19096 KB |
Output is correct |
13 |
Correct |
6 ms |
19036 KB |
Output is correct |
14 |
Correct |
6 ms |
19036 KB |
Output is correct |
15 |
Correct |
6 ms |
19036 KB |
Output is correct |