#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> events;
vector <vector <int>> dp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int p, q;
cin >> n >> p >> q;
events = vector <int> (n+1);
for (int i = 1; i <= n; i++)
cin >> events[i];
sort(events.begin(), events.end());
if (p + q >= n) {
cout << 1 << '\n';
return 0;
}
dp = vector <vector <int>> (n+1, vector <int> (p+1, 1e9));
int lo = 1, hi = 1e9;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= p; j++) {
dp[i][j] = 1e9;
if (j-1 >= 0)
dp[i][j] = dp[i][j-1];
int it = upper_bound(events.begin(), events.end(), events[i] - 2*mid) - events.begin();
dp[i][j] = min(dp[i][j], dp[max(0, it-1)][j] + 1);
if (j > 0) {
it = upper_bound(events.begin(), events.end(), events[i] - mid) - events.begin();
dp[i][j] = min(dp[i][j], dp[max(0, it-1)][j-1]);
}
}
}
if (dp[n][p] > q)
lo = mid + 1;
else
hi = mid;
}
cout << lo << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
15 ms |
664 KB |
Output is correct |
8 |
Correct |
124 ms |
1384 KB |
Output is correct |
9 |
Correct |
731 ms |
6412 KB |
Output is correct |
10 |
Execution timed out |
1059 ms |
15192 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |