結果

問題 No.649 ここでちょっとQK!
ユーザー tentententen
提出日時 2023-12-19 15:59:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,634 ms / 3,000 ms
コード長 2,415 bytes
コンパイル時間 2,790 ms
コンパイル使用メモリ 91,312 KB
実行使用メモリ 78,712 KB
最終ジャッジ日時 2023-12-19 16:00:05
合計ジャッジ時間 29,446 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
54,000 KB
testcase_01 AC 52 ms
53,984 KB
testcase_02 AC 52 ms
53,996 KB
testcase_03 AC 249 ms
59,788 KB
testcase_04 AC 2,634 ms
69,208 KB
testcase_05 AC 500 ms
69,356 KB
testcase_06 AC 2,509 ms
69,112 KB
testcase_07 AC 52 ms
53,992 KB
testcase_08 AC 51 ms
54,012 KB
testcase_09 AC 53 ms
53,996 KB
testcase_10 AC 56 ms
54,000 KB
testcase_11 AC 56 ms
53,984 KB
testcase_12 AC 771 ms
66,828 KB
testcase_13 AC 774 ms
67,020 KB
testcase_14 AC 706 ms
66,496 KB
testcase_15 AC 729 ms
65,380 KB
testcase_16 AC 693 ms
65,000 KB
testcase_17 AC 758 ms
65,024 KB
testcase_18 AC 863 ms
64,992 KB
testcase_19 AC 928 ms
65,144 KB
testcase_20 AC 1,200 ms
76,828 KB
testcase_21 AC 1,078 ms
67,180 KB
testcase_22 AC 1,160 ms
67,168 KB
testcase_23 AC 1,475 ms
76,740 KB
testcase_24 AC 1,510 ms
76,616 KB
testcase_25 AC 1,628 ms
76,356 KB
testcase_26 AC 1,714 ms
78,712 KB
testcase_27 AC 79 ms
55,024 KB
testcase_28 AC 90 ms
54,920 KB
testcase_29 AC 92 ms
55,020 KB
testcase_30 AC 713 ms
65,936 KB
testcase_31 AC 829 ms
74,392 KB
testcase_32 AC 53 ms
54,004 KB
testcase_33 AC 53 ms
54,004 KB
testcase_34 AC 53 ms
54,000 KB
testcase_35 AC 53 ms
53,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = 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();
        while (n-- > 0) {
            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) {
                        left = m;
                    } else {
                        right = m;
                    }
                }
                list.add(right, x);
            } else {
                if (list.size() < k + 2) {
                    sb.append("-1\n");
                } else {
                    sb.append(list.get(k)).append("\n");
                    list.remove(k);
                }
            }
        }
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0