結果
問題 |
No.3165 [Cherry 7th Tune A] Croissants Continu
|
ユーザー |
![]() |
提出日時 | 2025-06-28 14:56:55 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 718 bytes |
コンパイル時間 | 2,623 ms |
コンパイル使用メモリ | 82,652 KB |
実行使用メモリ | 68,560 KB |
最終ジャッジ日時 | 2025-06-28 14:57:45 |
合計ジャッジ時間 | 42,079 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 26 WA * 5 |
ソースコード
package no3165_croissants_continu; import java.util.*; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); for(int i = 0;i < t;i++) { int n = Integer.parseInt(sc.next()); PriorityQueue<Integer> q = new PriorityQueue<>(Collections.reverseOrder()); for(int j = 0;j < n;j++) { q.add(sc.nextInt()); }long ans = 0; while(q.size() > 1) { int a = q.poll(); int b = q.poll(); ans += b * 2L; if(a != b) { q.add(a - b); } }if(q.size() == 1)ans++; sb.append(ans + "\n"); }System.out.print(sb); } }