結果

問題 No.649 ここでちょっとQK!
ユーザー htensaihtensai
提出日時 2020-06-12 13:07:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 630 ms / 3,000 ms
コード長 1,241 bytes
コンパイル時間 2,710 ms
コンパイル使用メモリ 75,952 KB
実行使用メモリ 64,756 KB
最終ジャッジ日時 2023-09-06 09:07:24
合計ジャッジ時間 18,146 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,348 KB
testcase_01 AC 45 ms
49,492 KB
testcase_02 AC 44 ms
49,332 KB
testcase_03 AC 228 ms
56,380 KB
testcase_04 AC 630 ms
64,604 KB
testcase_05 AC 503 ms
64,756 KB
testcase_06 AC 459 ms
64,048 KB
testcase_07 AC 44 ms
47,720 KB
testcase_08 AC 44 ms
49,632 KB
testcase_09 AC 46 ms
49,456 KB
testcase_10 AC 45 ms
49,620 KB
testcase_11 AC 45 ms
49,500 KB
testcase_12 AC 389 ms
62,572 KB
testcase_13 AC 390 ms
60,108 KB
testcase_14 AC 385 ms
60,388 KB
testcase_15 AC 410 ms
60,544 KB
testcase_16 AC 399 ms
60,780 KB
testcase_17 AC 449 ms
60,880 KB
testcase_18 AC 462 ms
59,920 KB
testcase_19 AC 491 ms
60,060 KB
testcase_20 AC 499 ms
62,420 KB
testcase_21 AC 496 ms
62,512 KB
testcase_22 AC 536 ms
62,256 KB
testcase_23 AC 548 ms
62,152 KB
testcase_24 AC 544 ms
62,232 KB
testcase_25 AC 562 ms
64,624 KB
testcase_26 AC 567 ms
64,128 KB
testcase_27 AC 69 ms
51,704 KB
testcase_28 AC 79 ms
51,872 KB
testcase_29 AC 82 ms
50,916 KB
testcase_30 AC 347 ms
58,356 KB
testcase_31 AC 398 ms
58,156 KB
testcase_32 AC 47 ms
49,360 KB
testcase_33 AC 46 ms
49,368 KB
testcase_34 AC 45 ms
49,368 KB
testcase_35 AC 44 ms
49,512 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 (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);
	}
}
0