結果
| 問題 | 
                            No.2835 Take and Flip
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-08-09 21:40:22 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 55 ms / 2,000 ms | 
| コード長 | 762 bytes | 
| コンパイル時間 | 1,960 ms | 
| コンパイル使用メモリ | 196,024 KB | 
| 最終ジャッジ日時 | 2025-02-23 21:28:10 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 22 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template<typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void solve();
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int t = 1;
  //cin >> t;
  while (t--) {
    solve();
  }
}
int N;
priority_queue<int>que;
void solve() {
  cin>>N;
  rep(i,N){
    int A;cin>>A;
    que.push(A);
  }
  ll X=0,Y=0;
  rep(i,N){
    int v=que.top();
    que.pop();
    if(i%2==0){
      X+=v;
    }else{
      Y+=-v;
    }
  }
  cout<<X-Y<<endl;
}