結果

問題 No.2835 Take and Flip
ユーザー HIcoder
提出日時 2024-08-23 23:31:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 1,164 ms
コンパイル使用メモリ 118,104 KB
最終ジャッジ日時 2025-02-24 00:19:59
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP; 
const ll MOD=998244353;

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    multiset<ll> mst;
    for(int i=0;i<N;i++){
        cin>>A[i];
        mst.insert(A[i]);
    }

    ll X=0,Y=0;
    bool turn = 1;
    while(mst.size()>0){
        
        if(turn){
            auto it=mst.rbegin();
            X+=*it;
            mst.erase(mst.find(*it));
        }else{
            auto it=mst.begin();
            Y+=(-1)*(*it);
            mst.erase(mst.find(*it));
        }
        turn^=1;
    }

    cout<<X-Y<<endl;


}
0