結果

問題 No.1374 Absolute Game
ユーザー outlineoutline
提出日時 2021-02-05 22:54:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,616 bytes
コンパイル時間 1,297 ms
コンパイル使用メモリ 139,372 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-15 09:45:21
合計ジャッジ時間 2,994 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 7 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 13 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 22 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 22 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 22 ms
4,380 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 21 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 8 ms
4,376 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> c(N);
    for(int i = 0; i < N; ++i)  cin >> c[i];

    sort(rbegin(c), rend(c));
    ll ans = 0, a = 0, b = 0;
    for(int i = 0; i < N / 2; ++i)  b += c[i];
    for(int i = N / 2; i < N; ++i)  a += c[i];
    ans = abs(a) - abs(b);

    reverse(begin(c), end(c));
    a = 0, b = 0;
    for(int i = 0; i < N / 2; ++i)  b += c[i];
    for(int i = N / 2; i < N; ++i)  a += c[i];
    chmax(ans, abs(a) - abs(b));

    a = 0, b = 0;
    for(int i = 0; i < N; ++i){
        if(i % 2 == 0)  a += c[i];
        else    b += c[i];
    }
    chmin(ans, abs(a) - abs(b));

    cout << ans << endl;

    return 0;
}
0