結果

問題 No.2835 Take and Flip
ユーザー ttkkggwwttkkggww
提出日時 2024-08-09 21:29:18
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 4,032 ms
コンパイル使用メモリ 265,400 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-08-09 21:29:25
合計ジャッジ時間 6,483 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
ll N;
vector<ll> A;

void solve(){
    multiset<ll> s;
    for(ll i = 0;i<N;i++){
        s.insert(A[i]);
    }
    ll X=0,Y=0;
    for(ll i = 0;i<N;i++){
        if(i%2==0){
            X += *s.begin();
            s.erase(s.begin());
        }else{
            Y -= *s.rbegin();
            s.erase(prev(s.end()));
        }
    }
    cout<<X-Y<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    A.resize(N);
    for(ll i = 0; i < N; i++) cin >> A[i];
    solve();
}
0