#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ff first
#define ss second
#define pii pair<int, int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, p, q;
cin >> n >> p >> q;
vector<int> a(n + 1, INT_MIN);
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(1 + all(a));
int l = 0, r = (int)1e9;
while (l <= r) {
int md = (l + r) >> 1;
vector<pii> dp[n + 1];
dp[0] = {{0, 0}};
for (int i = 1; i <= n; i++) {
vector<pii> v;
for (auto j : dp[upper_bound(all(a), a[i] - md) - a.begin() - 1])
if (j.ff < p) v.push_back({j.ff + 1, j.ss});
for (auto j : dp[upper_bound(all(a), a[i] - (md << 1)) - a.begin() - 1])
if (j.ss < q) v.push_back({j.ff, j.ss + 1});
if (v.empty()) continue;
sort(v.begin(), v.end());
dp[i] = {v[0]};
for (int j = 1; j < sz(v); j++)
if (dp[i].back().ss > v[j].ss) dp[i].push_back(v[j]);
}
if (dp[n].empty()) l = md + 1;
else r = md - 1;
}
cout << l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
6 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
464 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Execution timed out |
1049 ms |
19864 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |