結果

問題 No.649 ここでちょっとQK!
ユーザー tentententen
提出日時 2021-11-12 15:06:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,711 ms / 3,000 ms
コード長 1,929 bytes
コンパイル時間 2,851 ms
コンパイル使用メモリ 79,280 KB
実行使用メモリ 68,428 KB
最終ジャッジ日時 2024-05-03 21:19:43
合計ジャッジ時間 30,222 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
36,940 KB
testcase_01 AC 50 ms
36,904 KB
testcase_02 AC 51 ms
36,952 KB
testcase_03 AC 258 ms
45,008 KB
testcase_04 AC 2,711 ms
64,264 KB
testcase_05 AC 589 ms
63,984 KB
testcase_06 AC 2,591 ms
63,648 KB
testcase_07 AC 51 ms
36,528 KB
testcase_08 AC 49 ms
36,900 KB
testcase_09 AC 52 ms
36,700 KB
testcase_10 AC 51 ms
36,904 KB
testcase_11 AC 51 ms
36,560 KB
testcase_12 AC 856 ms
63,660 KB
testcase_13 AC 833 ms
63,988 KB
testcase_14 AC 857 ms
64,920 KB
testcase_15 AC 830 ms
62,112 KB
testcase_16 AC 768 ms
60,708 KB
testcase_17 AC 889 ms
60,988 KB
testcase_18 AC 969 ms
61,480 KB
testcase_19 AC 1,002 ms
61,796 KB
testcase_20 AC 1,069 ms
62,728 KB
testcase_21 AC 1,154 ms
62,908 KB
testcase_22 AC 1,203 ms
68,344 KB
testcase_23 AC 1,264 ms
63,468 KB
testcase_24 AC 1,348 ms
68,428 KB
testcase_25 AC 1,466 ms
65,680 KB
testcase_26 AC 1,560 ms
65,308 KB
testcase_27 AC 82 ms
38,064 KB
testcase_28 AC 83 ms
37,832 KB
testcase_29 AC 79 ms
38,024 KB
testcase_30 AC 660 ms
62,020 KB
testcase_31 AC 734 ms
60,300 KB
testcase_32 AC 49 ms
36,876 KB
testcase_33 AC 48 ms
36,940 KB
testcase_34 AC 48 ms
37,052 KB
testcase_35 AC 48 ms
36,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int q = sc.nextInt();
        int k = sc.nextInt();
        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++) {
            if (sc.nextInt() == 1) {
                long x = sc.nextLong();
                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).append("\n");
                } else {
                    sb.append(list.remove(k)).append("\n");
                }
            }
        }
        System.out.print(sb);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0