結果
| 問題 |
No.2835 Take and Flip
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-18 19:18:50 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 3,713 bytes |
| コンパイル時間 | 5,945 ms |
| コンパイル使用メモリ | 313,096 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-18 19:18:59 |
| 合計ジャッジ時間 | 8,438 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//ループ系マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP2(i, s, n) for (ll i = s; i < (ll)n; i++)
#define REP3(v, A) for(auto v: A)
#define REP4(It, A) for (auto It=A.begin();It!=A.end();++It)
#define REP5(i, n) for (ll i = 0; i * i < (ll)(n); i++)
//vector系マクロ
#define ALL(A) A.begin(), A.end()
#define RV(A) reverse(ALL(A))
#define RALL(A) A.rbegin(), A.rend()
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(RALL(A))
//入力系マクロ
#define GET(A) cin >> A
#define GETV(i,n,A) REP(i,n)cin >> A[i]
#define GETV2(A) REP(i,A.size())cin >> A[i]
//出力系マクロ
#define Yes(bo) ((bo) ? "Yes":"No")
#define YES(bo) ((bo) ? "YES":"NO")
#define yes(bo) ((bo) ? "yes":"no")
#define Taka(bo) ((bo) ? "Takahashi":"Aoki")
#define LISTOUT(A) REP(i,A.SZ())cout << A[i] << " ";cout << endl
//雑処理系マクロ
#define PB push_back
#define IS insert
#define SZ size
#define TE true
#define FE false
#define fir first
#define sec second
#define PP pop
#define PS push
#define FT front
//定数系マクロ
#define I_MAX 2147483647
#define I_MIN -2147483647
#define UI_MAX 4294967295
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
#define ULL_MAX 18446744073709551615
//型宣言系マクロ
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vP = vector<P>;
using vc = vector<char>;
//using mint = modint998244353;
//デバッグ系マクロ
#ifdef _DEBUG
#define debug(x) cerr << "dbg: "<< #x << ": " << x << endl
#define debug_v(x) cerr << "dbg_vec: " << #x << ": "; REP3(v,x) cerr << v << " "; cerr << endl
#define debug_s(x) cerr << "dbg_set: " << #x << ": {"; REP3(v,x) cerr << v << ","; cerr << "}" << endl
#define debug_m(x) cerr << "dbg_map: " << #x << ": "; REP4(Ite1,x)cerr << "key: " << Ite1->first << " : " << Ite1->second << " "; cerr<< endl
#else
#define debug(x)
#define debug_v(x)
#define debug_s(x)
#define debug_m(x)
#endif
ll GCD(ll a, ll b) {if (b == 0) return a;else return GCD(b, a % b);}
ll LCM(ll a, ll b) {return a * b/GCD(a , b);}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}
template<class... T> inline void input(T&... a) { ((cin >> a), ...); }
template<class... T> inline void output(T&... a) { ((cout << a << " "), ...); cout << endl;}
bool kaibuncheck(string S){
REP(i,S.SZ()/2)if(S[i]!=S[S.SZ()-i-1])return false;
return true;
}
ll kaibuncount(string S){
ll tmp1=0;
REP(i,S.SZ()/2)if(S[i]!=S[S.SZ()-i-1])tmp1++;
return tmp1;
}
vector<P> primefact(ll N){
vector<P> ret;
for(ll i=2;i*i<=N;i++){
ll cot=0;
if(N%i==0){
while(N%i==0){
cot++;
N/=i;
}
ret.PB({i,cot});
}
}
if(N!=1)ret.PB({N,1});
return ret;
}
/*
struct Node{
int val, par;
vector<int> vec;
Node(int v, int p){val = v, par = p;};
};
int Q;
map<int, int> mp;//SAVEandLOAD
vector<Node> vect;
*/
bool poich(ll P,ll Q){return(0<=P&&P<Q);}
bool poich2(ll x,ll y,ll H,ll W){return(poich(x,W)&&poich(y,H));}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll N;
cin >> N;
vector<ll> A(N);
GETV2(A);
ll X=0,Y=0;
SORT(A);
ll q=0,p=N-1;
for(int i=0;i<N;i++){
if(i%2){
Y+=A[p];
p--;
}else{
X+=A[q];
q++;
}
}
Y*=-1;
cout << X-Y << endl;
}