結果
| 問題 | No.1374 Absolute Game |
| コンテスト | |
| ユーザー |
kcvlex
|
| 提出日時 | 2021-02-12 19:28:48 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 2,000 ms |
| コード長 | 548 bytes |
| コンパイル時間 | 2,988 ms |
| コンパイル使用メモリ | 119,476 KB |
| 最終ジャッジ日時 | 2025-01-18 17:51:21 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using ll = std::int64_t;
int main() {
int n;
std::cin >> n;
std::vector<ll> c(n);
for (ll &e : c) std::cin >> e;
ll sum = std::accumulate(std::begin(c), std::end(c), 0ll);
if (sum < 0) {
for (auto &e : c) e *= -1;
}
std::sort(std::rbegin(c), std::rend(c));
ll av = 0, bv = 0;
for (int i = 0; i < n; i++) {
(i & 1 ? bv : av) += c[i];
}
std::cout << std::abs(av) - std::abs(bv) << std::endl;
return 0;
}
kcvlex