結果
問題 | No.1906 Twinkle Town |
ユーザー |
![]() |
提出日時 | 2022-04-15 22:17:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 837 bytes |
コンパイル時間 | 2,126 ms |
コンパイル使用メモリ | 202,808 KB |
最終ジャッジ日時 | 2025-01-28 18:21:09 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 WA * 44 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){int T;cin >> T;for (int i = 0; i < T; i++){int N;cin >> N;vector<int> A(N);for (int j = 0; j < N; j++){cin >> A[j];}sort(A.begin(), A.end());for (int j = N - 1; j >= 1; j--){A[j] -= A[j - 1];}if (N % 2 == 0){long long ans = 0;priority_queue<int> pq;for (int j = N - 1; j >= 0; j--){pq.push(A[j]);if (j % 2 == 1){ans += pq.top();pq.pop();}}cout << ans << endl;}if (N % 2 == 1){long long ans = 0;priority_queue<int> pq;for (int j = 0; j < N; j++){pq.push(A[j]);if (j % 2 == 0){ans += pq.top();pq.pop();}}cout << ans << endl;}}}