結果

問題 No.1906 Twinkle Town
ユーザー risujirohrisujiroh
提出日時 2022-04-15 23:18:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 665 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 205,512 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-08-26 08:45:28
合計ジャッジ時間 6,651 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 28 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 28 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 28 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 28 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 28 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 27 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 28 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 28 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 28 ms
4,384 KB
testcase_21 WA -
testcase_22 AC 30 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 30 ms
4,380 KB
testcase_25 WA -
testcase_26 AC 30 ms
4,380 KB
testcase_27 WA -
testcase_28 AC 30 ms
4,380 KB
testcase_29 WA -
testcase_30 AC 40 ms
4,380 KB
testcase_31 WA -
testcase_32 AC 41 ms
4,376 KB
testcase_33 WA -
testcase_34 AC 40 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 40 ms
4,376 KB
testcase_37 WA -
testcase_38 AC 41 ms
4,380 KB
testcase_39 WA -
testcase_40 AC 50 ms
4,536 KB
testcase_41 AC 51 ms
4,800 KB
testcase_42 AC 51 ms
4,532 KB
testcase_43 WA -
testcase_44 AC 51 ms
4,540 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 26 ms
4,380 KB
testcase_48 AC 32 ms
4,376 KB
testcase_49 AC 36 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
  }
}
0