4059. 蟹老板的梦幻传送门真的能让宅男走出家门吗

SmallY
#include <iostream>
#include <algorithm>

using namespace std;
const static int32_t maxn = 1e6 + 10;

int32_t a[maxn];
int main() {
    int32_t n; cin >> n;
    for (int32_t i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int32_t j = upper_bound(a, a + n, (a[0] + a[n - 1]) / 2) - a;
    int32_t door1 = (a[0] + a[j - 1]) / 2, door2 = (a[j] + a[n - 1]) / 2;
    int32_t res = max({ a[j - 1] - a[0], door1 - a[0] + a[n - 1] - door2, a[n - 1] - a[j], a[j - 1] - door1 + door2 - a[j] });
    cout << res << endl;
    return 0;
}
你当前正在回复 博客/题目
存在问题!