結果
| 問題 |
No.1374 Absolute Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-06 01:44:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,058 bytes |
| コンパイル時間 | 1,748 ms |
| コンパイル使用メモリ | 175,440 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 14:44:55 |
| 合計ジャッジ時間 | 3,286 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 WA * 7 |
ソースコード
#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(), 0) < 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;
}