#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
void _ (int &a, int b) {
if (a > b)
a = b;
}
const int N = 2000;
int dp[1 + N][1 + N];
int a[1 + N];
int n, p, q;
bool check (int w) {
for (int i = 0; i <= n; i++)
for (int j = 0; j <= p; j++)
dp[i][j] = q + 1;
dp[0][0] = 0;
int x = 0, y = 0;
for (int i = 1; i <= n; i++) {
while (a[x] + w <= a[i])
x++;
if (x)
x--;
while (a[y] + 2 * w <= a[i])
y++;
if (y)
y--;
for (int j = 0; j <= p; j++) {
if (j)
_ (dp[i][j], dp[x][j - 1]);
_ (dp[i][j], dp[y][j] + 1);
}
}
for (int i = 0; i <= p; i++)
if (dp[n][i] <= q)
return true;
return false;
}
int main () {
cin >> n >> p >> q;
_ (p, n);
_ (q, n);
for (int i = 1; i <= n; i++)
cin >> a[i];
sort (a + 1, a + n + 1);
int lb = 1, rb = (1 << 30);
int bestW = 0;
while (lb <= rb) {
int mid = (lb + rb) / 2;
if (check (mid))
bestW = mid, rb = mid - 1;
else
lb = mid + 1;
}
cout << bestW << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
5 ms |
768 KB |
Output is correct |
11 |
Correct |
6 ms |
768 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
768 KB |
Output is correct |
15 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8448 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
229 ms |
16000 KB |
Output is correct |
4 |
Correct |
276 ms |
16120 KB |
Output is correct |
5 |
Correct |
23 ms |
8960 KB |
Output is correct |
6 |
Correct |
271 ms |
16000 KB |
Output is correct |
7 |
Correct |
12 ms |
8448 KB |
Output is correct |
8 |
Correct |
29 ms |
9344 KB |
Output is correct |
9 |
Correct |
117 ms |
14208 KB |
Output is correct |
10 |
Correct |
265 ms |
16120 KB |
Output is correct |
11 |
Correct |
25 ms |
9088 KB |
Output is correct |
12 |
Correct |
154 ms |
16000 KB |
Output is correct |
13 |
Correct |
12 ms |
8448 KB |
Output is correct |
14 |
Correct |
14 ms |
8576 KB |
Output is correct |
15 |
Correct |
13 ms |
8576 KB |
Output is correct |