#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
#define int long long
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while(tt--) {
int n, p, q;
cin >> n >> p >> q;
vector<int> a(n);
for(int i = 0;i < n;i++)
cin >> a[i];
sort(a.begin(), a.end());
auto intersect = [&](int x1, int y1, int x2, int y2) {
if(y1 < x2 || x1 > y2)
return 0ll;
return min(y2, y1) - max(x1, x2) + 1;
};
auto check = [&](int x) {
set<pair<int, int>> d, d1;
for(int i = 0;i < n;i++) {
auto u = upper_bound(a.begin(), a.end(), a[i] + 2 * x - 1) - a.begin();
--u;
d.emplace(u - i + 1, i);
}
vector<int> vis(n);
for(int i = 0;i < min(n, q);i++) {
auto u = *--d.end();
d.erase(--d.end());
for(int j = u.s, k = 0;k < u.f;k++,j++)
vis[j] = 1;
set<pair<int, int>> t = d;
for(auto x : t) {
int l = x.s, r = x.s + x.f - 1;
int k = intersect(l, r, u.s, u.f + u.s - 1);
d.erase({x.f, x.s});
d.insert({x.f - k, l});
}
}
vector<int> pr(n);
pr[0] = vis[0];
for(int i = 1;i < n;i++)
pr[i] = pr[i - 1] + vis[i];
for(int i = 0;i < n;i++) {
auto u = upper_bound(a.begin(), a.end(), a[i] + x - 1) - a.begin();
--u;
d1.emplace(u - i + 1 - pr[u] + (i == 0 ? 0 : pr[i - 1]), i);
}
for(int i = 0;i < min(n, p);i++) {
auto u = *--d1.end();
d1.erase(--d1.end());
for(int j = u.s, k = 0;k < u.f;k++,j++)
vis[j] = 1;
set<pair<int, int>> t = d1;
for(auto x : t) {
int l = x.s, r = x.s + x.f - 1;
int k = intersect(l, r, u.s, u.f + u.s - 1);
d1.erase({x.f, x.s});
d1.insert({x.f - k, l});
}
}
int ok = 1;
for(int i = 0;i < n;i++)
ok &= (vis[i] == 1);
return ok;
};
int l = 1, r = 1e9, ans = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(check(mid)) {
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |