题解:P12458 [JOI2025 预选赛 R2] 冰淇淋
设 Alice、Bob 依次选了口味
首先我们分析最后选
现在,Bob 在选
也就是
于是我们先对
#include<iostream>
#include<algorithm>
constexpr int N = 2e5 + 5;
int x, y, z, p, a[N], b[N], c[N], max = -1;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
std::cin >> x >> y >> z >> p;
for(int i = 1; i <= x; ++i) std::cin >> a[i];
for(int i = 1; i <= y; ++i) std::cin >> b[i];
for(int i = 1; i <= z; ++i) std::cin >> c[i];
int cmin = *std::min_element(c + 1, c + z + 1);
int cmax = *std::max_element(c + 1, c + z + 1);
std::sort(b + 1, b + y + 1);
for(int i = 1; i <= x; ++i) {
double bp = p - (cmin + cmax) / 2. - a[i]; int c;
int P = std::lower_bound(b + 1, b + y + 1, bp) - b;
if(P == 1) c = b[1]; else if(P == y + 1) c = b[y];
else c = (b[P] - bp < bp - b[P - 1] ? b[P] : b[P - 1]);
int s1 = std::abs(a[i] + c + cmin - p);
int s2 = std::abs(a[i] + c + cmax - p);
max = std::max(max, std::max(s1, s2));
}
std::cout << max << "\n";
return 0;
}