結果

問題 No.649 ここでちょっとQK!
ユーザー htensaihtensai
提出日時 2020-06-12 12:54:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,631 ms / 3,000 ms
コード長 1,213 bytes
コンパイル時間 3,295 ms
コンパイル使用メモリ 75,636 KB
実行使用メモリ 65,556 KB
最終ジャッジ日時 2023-09-06 09:06:22
合計ジャッジ時間 27,472 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,012 KB
testcase_01 AC 41 ms
49,312 KB
testcase_02 AC 41 ms
49,060 KB
testcase_03 AC 231 ms
55,844 KB
testcase_04 AC 2,631 ms
65,488 KB
testcase_05 AC 556 ms
65,556 KB
testcase_06 AC 462 ms
65,416 KB
testcase_07 AC 42 ms
48,796 KB
testcase_08 AC 41 ms
49,092 KB
testcase_09 AC 42 ms
49,220 KB
testcase_10 AC 41 ms
48,972 KB
testcase_11 AC 41 ms
48,784 KB
testcase_12 AC 926 ms
65,260 KB
testcase_13 AC 859 ms
65,272 KB
testcase_14 AC 856 ms
65,536 KB
testcase_15 AC 940 ms
64,648 KB
testcase_16 AC 755 ms
62,624 KB
testcase_17 AC 856 ms
62,340 KB
testcase_18 AC 995 ms
62,468 KB
testcase_19 AC 1,020 ms
62,756 KB
testcase_20 AC 1,093 ms
64,352 KB
testcase_21 AC 1,133 ms
62,652 KB
testcase_22 AC 1,217 ms
64,492 KB
testcase_23 AC 1,356 ms
64,524 KB
testcase_24 AC 1,482 ms
64,444 KB
testcase_25 AC 1,478 ms
64,404 KB
testcase_26 AC 1,634 ms
64,716 KB
testcase_27 AC 66 ms
51,116 KB
testcase_28 AC 75 ms
49,252 KB
testcase_29 AC 78 ms
51,000 KB
testcase_30 AC 713 ms
63,560 KB
testcase_31 AC 720 ms
62,120 KB
testcase_32 AC 41 ms
49,120 KB
testcase_33 AC 42 ms
49,004 KB
testcase_34 AC 43 ms
49,248 KB
testcase_35 AC 43 ms
49,132 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<>();
		list.add(Long.MIN_VALUE);
		list.add(Long.MAX_VALUE);
		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]);
		        int left = 0;
		        int right = list.size();
		        while (right - left > 1) {
		            int m = (left + right) / 2;
		            if (list.get(m) > x) {
		                right = m;
		            } else {
		                left = m;
		            }
		        }
		        list.add(right, x);
		    } else {
		        if (list.size() - 2 < k) {
		            sb.append(-1);
		        } else {
		            sb.append(list.get(k));
    		        list.remove(k);
		        }
		        sb.append("\n");
		    }
		}
		System.out.print(sb);
	}
}
0