結果
| 問題 |
No.1906 Twinkle Town
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2022-04-15 23:28:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 2,000 ms |
| コード長 | 688 bytes |
| コンパイル時間 | 2,135 ms |
| コンパイル使用メモリ | 203,216 KB |
| 最終ジャッジ日時 | 2025-01-28 18:43:18 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
#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<int64_t> A(N);
for (int64_t& e : A) { std::cin >> e; }
std::sort(A.begin(), A.end());
bool even = ~N & 1;
if (even) {
++N;
A.push_back(ino64_t(1e18));
}
std::adjacent_difference(A.begin(), A.end(), A.begin());
auto ans = A[0];
std::priority_queue<int64_t> 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 = int64_t(1e18) - ans; }
std::cout << ans << '\n';
}
}
risujiroh