結果
問題 |
No.1906 Twinkle Town
|
ユーザー |
![]() |
提出日時 | 2022-04-15 23:18:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 665 bytes |
コンパイル時間 | 2,019 ms |
コンパイル使用メモリ | 201,460 KB |
最終ジャッジ日時 | 2025-01-28 18:38:25 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 22 |
ソースコード
#include <bits/stdc++.h> int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int T; std::cin >> T; while (T--) { int N; std::cin >> N; std::vector<int> A(N); for (int& e : A) { std::cin >> e; } std::sort(A.begin(), A.end()); bool even = ~N & 1; if (even) { ++N; A.push_back(int(1e9)); } std::adjacent_difference(A.begin(), A.end(), A.begin()); int ans = A[0]; std::priority_queue<int> q; for (int i = 1; i < N; i += 2) { q.push(A[i]); q.push(A[i + 1]); ans += q.top(); q.pop(); } if (even) { ans = int(1e9) - ans; } std::cout << ans << '\n'; } }