結果

問題 No.2835 Take and Flip
ユーザー ttkkggwwttkkggww
提出日時 2024-08-09 21:29:18
言語 C++17
(gcc 12.3.0 + boost 1.83.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 76 ms
14,208 KB
testcase_04 AC 77 ms
14,208 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 83 ms
13,184 KB
testcase_07 AC 88 ms
13,440 KB
testcase_08 AC 77 ms
12,416 KB
testcase_09 AC 94 ms
14,208 KB
testcase_10 AC 95 ms
14,208 KB
testcase_11 AC 93 ms
14,208 KB
testcase_12 AC 96 ms
14,208 KB
testcase_13 AC 95 ms
14,208 KB
testcase_14 AC 32 ms
7,552 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 56 ms
10,240 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 71 ms
11,648 KB
testcase_19 AC 86 ms
13,568 KB
testcase_20 AC 28 ms
7,040 KB
testcase_21 AC 86 ms
13,056 KB
testcase_22 AC 55 ms
10,496 KB
testcase_23 AC 23 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

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