結果

問題 No.1374 Absolute Game
ユーザー 🍮かんプリン
提出日時 2021-02-05 22:09:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 171,288 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 12:38:50
合計ジャッジ時間 3,199 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.02.05 22:09:50
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n;cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(c.begin(), c.end());
    
    ll a = 0,b = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (i & 1) {
            b += c[n-i-1];
        }
        else {
            a += c[n-i-1];
        }
    }
    ans = abs(a)-abs(b);
    a = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (i & 1) {
            b += c[i];
        }
        else {
            a += c[i];
        }
    }
    ans = max(ans,abs(a)-abs(b));
    cout << ans << endl;
    return 0;
}
0