#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 + 1 << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8448 KB |
Output is correct |
2 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |