結果
| 問題 |
No.1374 Absolute Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-05 23:13:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 1,034 bytes |
| コンパイル時間 | 900 ms |
| コンパイル使用メモリ | 79,900 KB |
| 最終ジャッジ日時 | 2025-01-18 13:02:44 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
ソースコード
#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using lint = long long;
constexpr lint INF = 1LL << 60;
void solve() {
int n;
cin >> n;
vector<lint> xs(n);
for (auto& x : xs) cin >> x;
sort(xs.begin(), xs.end());
lint ans = -INF;
for (int q = 0; q < 2; ++q) {
lint mi = INF;
{
lint a = 0, b = 0;
for (int i = 0; i < n; ++i) {
(i % 2 == 0 ? a : b) += xs[i];
}
mi = min(mi, abs(a) - abs(b));
}
{
lint a = 0, b = 0;
int l = 0, r = n - 1;
while (l <= r) {
a += xs[l++];
if (l > r) break;
b -= xs[r--];
}
mi = min(mi, abs(a) - abs(b));
}
ans = max(ans, mi);
reverse(xs.begin(), xs.end());
}
cout << ans << "\n";
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}