結果
問題 |
No.1374 Absolute Game
|
ユーザー |
|
提出日時 | 2021-02-05 22:22:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 815 bytes |
コンパイル時間 | 2,394 ms |
コンパイル使用メモリ | 198,056 KB |
最終ジャッジ日時 | 2025-01-18 12:37:33 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 6 WA * 20 |
ソースコード
#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; using ll = long long; int main(){ int n; cin >> n; vector<ll> a(n); for(auto &i:a)cin >> i; sort(a.begin(),a.end()); ll ans = LLONG_MAX; { ll A=0,B=0; for(int i = 0;i<n/2+1;i++){ A+= a[i]; } for(int i = n/2+1;i<n;i++){ B += a[i]; } ans = abs(A)-abs(B); } { ll A = 0,B=0; for(int i = 0;i<n;i++){ if(i&1)B += a[i]; else A += a[i]; } ans = min(ans,abs(A)-abs(B)); } { reverse(a.begin(),a.end()); ll A = 0,B=0; for(int i = 0;i<n;i++){ if(i&1)B += a[i]; else A += a[i]; } ans = min(ans,abs(A)-abs(B)); } { ll A=0,B=0; for(int i = 0;i<n/2+1;i++){ A+= a[i]; } for(int i = n/2+1;i<n;i++){ B += a[i]; } ans = abs(A)-abs(B); } cout<<ans<<endl; }