結果
問題 |
No.649 ここでちょっとQK!
|
ユーザー |
![]() |
提出日時 | 2020-06-12 13:07:14 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 671 ms / 3,000 ms |
コード長 | 1,241 bytes |
コンパイル時間 | 2,629 ms |
コンパイル使用メモリ | 79,060 KB |
実行使用メモリ | 65,908 KB |
最終ジャッジ日時 | 2024-06-24 03:49:58 |
合計ジャッジ時間 | 16,058 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int q = Integer.parseInt(first[0]); int k = Integer.parseInt(first[1]); ArrayList<Long> list = new ArrayList<>(); PriorityQueue<Long> fore = new PriorityQueue<>(); PriorityQueue<Long> rear = new PriorityQueue<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { String[] line = br.readLine().split(" "); int type = Integer.parseInt(line[0]); if (type == 1) { long x = Long.parseLong(line[1]); if (k == 1) { rear.add(x); continue; } if (fore.size() < k - 1 || -fore.peek() > x) { fore.add(-x); if (fore.size() >= k) { rear.add(-fore.poll()); } } else { rear.add(x); } } else { if (rear.size() == 0) { sb.append(-1); } else { sb.append(rear.poll()); } sb.append("\n"); } } System.out.print(sb); } }