結果
問題 |
No.2957 Combo Deck Builder
|
ユーザー |
![]() |
提出日時 | 2024-11-08 22:36:26 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,433 bytes |
コンパイル時間 | 3,975 ms |
コンパイル使用メモリ | 82,000 KB |
実行使用メモリ | 90,164 KB |
最終ジャッジ日時 | 2024-11-08 22:37:18 |
合計ジャッジ時間 | 38,167 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 TLE * 10 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.PriorityQueue; import java.util.TreeSet; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); PriorityQueue<Obj> que1 = new PriorityQueue<>((o1, o2) -> o1.v - o2.v); PriorityQueue<Obj> que2 = new PriorityQueue<>((o1, o2) -> o2.v - o1.v); for (int i = 0; i < n; i++) { String[] sa = br.readLine().split(" "); Obj o = new Obj(); o.c = Integer.parseInt(sa[0]); o.x = Integer.parseInt(sa[1]); o.y = Integer.parseInt(sa[2]); o.v = o.x - o.y; if (o.v < 0) { que1.add(o); } else { que2.add(o); } } br.close(); TreeSet<Integer> set = new TreeSet<>(); for (int i = 0; i < n; i++) { set.add(i); } long ans = 0; while (!que1.isEmpty()) { Obj o = que1.poll(); Integer k = set.lower(o.c); if (k == null) { k = set.last(); ans += o.x; } else { ans += o.y; } set.remove(k); } set.clear(); for (int i = n - que2.size(); i < n; i++) { set.add(i); } while (!que2.isEmpty()) { Obj o = que2.poll(); Integer k = set.ceiling(o.c); if (k == null) { k = set.first(); ans += o.y; } else { ans += o.x; } set.remove(k); } System.out.println(ans); } static class Obj { int c, x, y, v; } }