結果

問題 No.649 ここでちょっとQK!
ユーザー htensaihtensai
提出日時 2020-06-12 13:04:39
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,154 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 76,060 KB
実行使用メモリ 66,484 KB
最終ジャッジ日時 2023-09-06 09:06:38
合計ジャッジ時間 14,825 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,440 KB
testcase_01 AC 44 ms
49,456 KB
testcase_02 AC 45 ms
49,588 KB
testcase_03 AC 232 ms
56,656 KB
testcase_04 AC 655 ms
66,484 KB
testcase_05 AC 521 ms
64,676 KB
testcase_06 AC 467 ms
64,748 KB
testcase_07 AC 46 ms
49,668 KB
testcase_08 AC 44 ms
47,584 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 386 ms
60,632 KB
testcase_13 AC 384 ms
60,544 KB
testcase_14 AC 380 ms
60,364 KB
testcase_15 AC 398 ms
60,296 KB
testcase_16 AC 382 ms
60,324 KB
testcase_17 AC 434 ms
60,480 KB
testcase_18 AC 456 ms
60,476 KB
testcase_19 AC 464 ms
58,320 KB
testcase_20 AC 490 ms
62,184 KB
testcase_21 AC 505 ms
62,332 KB
testcase_22 AC 520 ms
62,524 KB
testcase_23 AC 537 ms
62,392 KB
testcase_24 AC 552 ms
62,220 KB
testcase_25 AC 590 ms
64,720 KB
testcase_26 AC 589 ms
64,548 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 74 ms
51,752 KB
testcase_30 AC 343 ms
59,572 KB
testcase_31 AC 379 ms
59,816 KB
testcase_32 AC 46 ms
49,388 KB
testcase_33 RE -
testcase_34 AC 45 ms
49,552 KB
testcase_35 AC 44 ms
49,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 (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);
	}
}
0