| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 38998 | Gapple | 【S】T1 | C++ | 通过 | 100 | 63 MS | 436 KB | 850 | 2025-11-27 20:02:28 |
#include <algorithm> #include <iostream> #include <vector> using namespace std; using i64 = long long; constexpr i64 INF = 0x3f3f3f3f3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<i64> w(n + 1); for (int i = 1; i <= n; ++i) cin >> w[i]; sort(w.begin() + 1, w.end()); i64 ans = INF; for (int i = 0; i <= n; i += 2) { i64 mx = -INF, mn = INF; for (int j = 1; i + 1 > j << 1; ++j) { i64 val = w[i + 1 - j] + w[j]; mx = max(mx, val); mn = min(mn, val); } if (i < n) { mx = max(mx, w[n]); mn = min(mn, w[i + 1]); } ans = min(ans, mx - mn); } cout << ans << '\n'; return 0; }