#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, p, q;
vector<int> v;
int brutus(int w, int i, int p_left, vector<vector<int>> &dp) {
if (i >= n) return 0;
if (dp[i][p_left] != -1) return dp[i][p_left];
int useq = lower_bound(v.begin(), v.end(), v[i] + (2 * w)) - v.begin();
dp[i][p_left] = brutus(w, useq, p_left, dp) + 1;
if (p_left) {
int usep = lower_bound(v.begin(), v.end(), v[i] + w) - v.begin();
dp[i][p_left] = min(dp[i][p_left], brutus(w, usep, p_left - 1, dp));
}
return dp[i][p_left];
}
int solve() {
int minw = 1, maxw = 1e9;
while (maxw - minw >= 5) {
int mid = (maxw + minw) / 2;
vector<vector<int>> dp(n, vector<int>(p + 1, -1));
if (brutus(mid, 0, p, dp) <= q) maxw = mid;
else minw = mid + 1;
}
for (int i = minw; i <= maxw; i++) {
vector<vector<int>> dp(n, vector<int>(p + 1, -1));
if (brutus(i, 0, p, dp) <= q) return i;
}
return 1e9;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> p >> q;
v.resize(n);
for (int &i : v) {
cin >> i;
}
sort(v.begin(), v.end());
cout << solve() << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
430 ms |
40140 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
448 ms |
40184 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
292 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
204 KB |
Output is correct |
12 |
Correct |
3 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
1079 ms |
12436 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |