結果

問題 No.1374 Absolute Game
ユーザー seiyuseiyu
提出日時 2021-02-06 01:48:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 1,749 ms
コンパイル使用メモリ 174,576 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 11:08:01
合計ジャッジ時間 3,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 15 ms
4,376 KB
testcase_09 AC 37 ms
4,376 KB
testcase_10 AC 42 ms
4,376 KB
testcase_11 AC 26 ms
4,380 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 33 ms
4,376 KB
testcase_14 AC 49 ms
4,380 KB
testcase_15 AC 48 ms
4,380 KB
testcase_16 AC 49 ms
4,380 KB
testcase_17 AC 49 ms
4,376 KB
testcase_18 AC 49 ms
4,380 KB
testcase_19 AC 48 ms
4,380 KB
testcase_20 AC 19 ms
4,376 KB
testcase_21 AC 25 ms
4,376 KB
testcase_22 AC 48 ms
4,380 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 16 ms
4,376 KB
testcase_27 AC 22 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll abs_(ll x){
    if(x > 0)
        return x;
    else
        return -1 * x;
}

int main(){
    int n;
    cin >> n;

    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    if(accumulate(a.begin(), a.end(), 0ll) < 0){
        sort(a.begin(), a.end());
    }else{
        sort(a.rbegin(), a.rend());
    }

    ll sum_a = 0, sum_b = 0;

    rep(i,n){
        if(i%2 == 0){
            sum_a += a[i];
        }else{
            sum_b += a[i];
        }
    }

    cout << abs(sum_a) - abs(sum_b) << endl;

    return 0;
}
0