結果

問題 No.2835 Take and Flip
ユーザー kaede2020kaede2020
提出日時 2024-08-09 21:37:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 7,104 ms
コンパイル使用メモリ 337,084 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-08-09 21:37:35
合計ジャッジ時間 9,364 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using mint = modint998244353;

random_device rnd;
mt19937 mt(rnd());
int RandInt(int a, int b) {
    return a + mt() % (b - a + 1);
}
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

//    int TIMELIMIT = 2.8 * CLOCKS_PER_SEC;
//    int ti = clock();
//    while (clock() - ti < TIMELIMIT) {

ll n;
int main(){
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    deque<int>dq;
    rep(i,n)dq.push_back(a[i]);
    bool flag=true;
    ll first_sum=0;
    ll second_sum=0;
    rep(i,n){
        if(flag){
            first_sum+=dq.back();
            dq.pop_back();
            flag=false;
        }else{
            second_sum+=-1*dq.back();
            dq.pop_back();
            flag=true;
        }
    }
    cout<<first_sum-second_sum<<endl;
    return 0;
}
0