結果
問題 |
No.2835 Take and Flip
|
ユーザー |
|
提出日時 | 2024-08-12 19:24:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 472 bytes |
コンパイル時間 | 4,077 ms |
コンパイル使用メモリ | 252,956 KB |
最終ジャッジ日時 | 2025-02-23 22:41:49 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for(auto &&v : a) cin >> v; sort(a.begin(), a.end()); int l = 0, r = n - 1; ll ans = 0; for(int i = 0; i < n; i++){ if(i % 2 == 0){ ans += a[r--]; }else{ ans -= -a[l++]; } } cout << ans << '\n'; }