题解:P11854 [CSP-J2022 山东] 宴会
LostKeyToReach · · 题解
容易证明,宴会的开始时间为:
我们不妨设定开始时间为
此时将
时间复杂度
代码如下:
int main() {
#if MULTI_TEST == 1
LL T;
std::cin >> T;
while (T--) {
// Test cases...
auto Solve = [&]() -> void {
int n;
std::cin >> n;
VLL x(n + 1, 0), t(n + 1, 0);
for (int i = 1; i <= n; ++i)
std::cin >> x[i];
for (int i = 1; i <= n; ++i)
std::cin >> t[i];
LL a = -1e18, b = 1e18;
for (int i = 1; i <= n; ++i) {
cmax(a, x[i] + t[i]);
cmin(b, x[i] - t[i]);
}
double x_0 = (a + b) / 2.0;
if (fabs(x_0 - round(x_0)) < 1e-9)
std::cout << (LL)round(x_0) << "\n";
else
std::cout << std::fixed << std::setprecision(1) << x_0 << "\n";
};
Solve();
}
#else
#endif
return 0;
}