結果

問題 No.1374 Absolute Game
ユーザー ocvret_ocvret_
提出日時 2021-02-05 21:58:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 172,164 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-15 08:08:28
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  cin >> n;
  vector<ll> c(n);
  rep(i,n)cin >> c[i];
  ll res = -1ll*MOD*MOD;
  auto solve = [&](){
    ll a = 0,b = 0;
    for(int i = n-1;i >= 0;i-=2){
      a += c[i];
      if(i-1 >= 0)b += c[i-1];
    }
    ll k = abs(a)-abs(b);
    a = 0,b = 0;
    for(int i = n-1,j = 0;j <= i;i--,j++){
      a += c[i];
      if(i != j)b += c[j];
    }
    k = min(k,abs(a)-abs(b));
    res = max(res,k);
  };
  sort(ALL(c));
  solve();
  sort(ALL(c),greater<ll>());
  solve();
  cout << res << "\n";



  return 0;
}
0