結果
問題 | No.1906 Twinkle Town |
ユーザー |
![]() |
提出日時 | 2022-02-05 13:13:36 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 834 bytes |
コンパイル時間 | 1,025 ms |
コンパイル使用メモリ | 110,632 KB |
実行使用メモリ | 8,832 KB |
最終ジャッジ日時 | 2024-06-11 13:30:52 |
合計ジャッジ時間 | 5,085 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 37 |
ソースコード
// WA 解法 // Use std::multiset<> but erase items in wrong manner #include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin >> T; while (T--) { int N; cin >> N; vector<int> A(N); for (auto &x : A) cin >> x; sort(A.begin(), A.end()); int all = A.back(); for (int i = N - 1; i; --i) A[i] -= A[i - 1]; multiset<int> ms; int last = 0; for (int i = 0; i < N; ++i) { ms.insert(A[i]); if (i % 2 == 0 and ms.size()) { int v = *prev(ms.end()); last += v; ms.erase(v); } } cout << ((N & 1) ? last : all - last) << '\n'; } }