#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
#define int long long
using namespace std;
const int sz = 2e5 + 10;
const int inf = 1e18;
int a[sz];
int n, p, q;
bool f;
void dfs(int v, vector<vector<int>> aj[], int cl, int cr) {
if (cl > p || cr > q) return;
if (v == n + 1) {
f |= (cl <= p && cr <= q);
} else {
for (auto& u : aj[v]) {
dfs(u[0], aj, cl + u[1], cr + u[2]);
}
}
}
bool che(int mi) {
vector<vector<int>> aj[sz];
for (int i = 1; i <= n; i ++) {
int d = lower_bound(a + 1, a + n + 1, a[i] + mi) - &a[i];
int c = lower_bound(a + 1, a + n + 1, a[i] + 2 * mi) - &a[i];
aj[i].push_back({i + d, 1, 0});
aj[i].push_back({i + c, 0, 1});
}
f = false;
dfs(1, aj, 0, 0);
return f;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> p >> q;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
a[n + 1] = inf;
int le, ri;
le = 0, ri = 1e9 + 7;
while (1 < ri - le) {
int mi = le + (ri - le) / 2;
if (che(mi)) {
ri = mi;
} else {
le = mi;
}
}
cout << ri << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
4956 KB |
Output is correct |
2 |
Correct |
15 ms |
5072 KB |
Output is correct |
3 |
Correct |
14 ms |
5156 KB |
Output is correct |
4 |
Execution timed out |
1080 ms |
4956 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
5208 KB |
Output is correct |
2 |
Correct |
14 ms |
4956 KB |
Output is correct |
3 |
Execution timed out |
1095 ms |
5196 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |