結果
問題 | No.2835 Take and Flip |
ユーザー |
|
提出日時 | 2024-08-09 21:52:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 101 ms / 2,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 1,418 ms |
コンパイル使用メモリ | 105,208 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-08-09 21:52:36 |
合計ジャッジ時間 | 3,490 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>using namespace std;using ll = long long;int main () {int N; cin >> N;vector<int> A(N);for (int i = 0; i < N; i++) cin >> A[i];// First君は相手に関係なく残っている最大を選ぶのが最適で、Second君は相手に関係なく残っている最小を選ぶのが最適になる。sort(A.begin(), A.end());int l = 0, r = N - 1;auto is_game_end = [&] () {return r < l;};ll X = 0, Y = 0;while (true) {X += A[l];l++;if (is_game_end()) break;Y += -A[r];r--;if (is_game_end()) break;}cout << X - Y << "\n";}