結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-02-10 15:29:26 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,419 ms / 3,000 ms |
| コード長 | 1,887 bytes |
| コンパイル時間 | 2,143 ms |
| コンパイル使用メモリ | 79,696 KB |
| 実行使用メモリ | 65,736 KB |
| 最終ジャッジ日時 | 2024-10-13 13:43:16 |
| 合計ジャッジ時間 | 28,910 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Comparator;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskD solver = new TaskD();
solver.solve(1, in, out);
out.close();
}
static class TaskD {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int q = in.nextInt();
int k = in.nextInt();
PriorityQueue<Long> maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
PriorityQueue<Long> minHeap = new PriorityQueue<>(Comparator.naturalOrder());
for (int i = 0; i < q; i++) {
int qn = in.nextInt();
if (qn == 1) {
long next = in.nextLong();
if (maxHeap.size() < k) {
maxHeap.add(next);
} else {
if (next < maxHeap.peek()) {
minHeap.add(maxHeap.poll());
maxHeap.add(next);
} else {
minHeap.add(next);
}
}
} else {
if (maxHeap.size() < k) {
out.println(-1);
} else {
out.println(maxHeap.poll());
if (minHeap.size() > 0) maxHeap.add(minHeap.poll());
}
}
}
}
}
}