結果
問題 | No.2835 Take and Flip |
ユーザー |
![]() |
提出日時 | 2024-08-09 21:24:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 561 bytes |
コンパイル時間 | 3,047 ms |
コンパイル使用メモリ | 251,096 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-08-09 21:24:23 |
合計ジャッジ時間 | 4,273 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template <class T> using V=vector<T>; template <class T> using VV=V<V<T>>; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; V<ll> A(n); rep(i,n) cin>>A[i]; sort(ALL(A)); reverse(ALL(A)); ll x=0,y=0; int l=0,r=n-1; rep(i,n){ if(i%2==0){ x+=A[l]; l++; } else{ y-=A[r]; r--; } } cout<<x-y<<endl; return 0; }