結果
| 問題 |
No.1374 Absolute Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-06 04:52:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 838 bytes |
| コンパイル時間 | 717 ms |
| コンパイル使用メモリ | 96,736 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 14:48:00 |
| 合計ジャッジ時間 | 2,240 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long c[100010];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c[i];
}
sort(c, c + n);
long long ans = -10000000000000007;
long long a = 0, b = 0;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
a += c[i];
}
else {
b += c[i];
}
}
if (ans < abs(a) - abs(b)) {
ans = abs(a) - abs(b);
}
a = 0, b = 0;
for (int i = n - 1; i >= 0; i--) {
if (i % 2 == (n - 1) % 2) {
a += c[i];
}
else {
b += c[i];
}
}
if (ans < abs(a) - abs(b)) {
ans = abs(a) - abs(b);
}
cout << ans << endl;
}