結果

問題 No.649 ここでちょっとQK!
ユーザー tentententen
提出日時 2023-04-10 14:51:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,571 ms / 3,000 ms
コード長 2,371 bytes
コンパイル時間 2,509 ms
コンパイル使用メモリ 97,500 KB
実行使用メモリ 64,428 KB
最終ジャッジ日時 2024-04-15 19:50:24
合計ジャッジ時間 29,852 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
37,092 KB
testcase_01 AC 48 ms
37,248 KB
testcase_02 AC 47 ms
37,092 KB
testcase_03 AC 241 ms
46,484 KB
testcase_04 AC 2,571 ms
63,048 KB
testcase_05 AC 555 ms
63,356 KB
testcase_06 AC 2,532 ms
62,852 KB
testcase_07 AC 49 ms
37,104 KB
testcase_08 AC 48 ms
37,384 KB
testcase_09 AC 50 ms
37,384 KB
testcase_10 AC 49 ms
37,024 KB
testcase_11 AC 48 ms
37,328 KB
testcase_12 AC 751 ms
52,108 KB
testcase_13 AC 903 ms
63,604 KB
testcase_14 AC 888 ms
63,120 KB
testcase_15 AC 816 ms
61,140 KB
testcase_16 AC 710 ms
59,740 KB
testcase_17 AC 872 ms
60,292 KB
testcase_18 AC 790 ms
50,880 KB
testcase_19 AC 876 ms
51,232 KB
testcase_20 AC 1,139 ms
61,648 KB
testcase_21 AC 1,068 ms
52,192 KB
testcase_22 AC 1,312 ms
62,516 KB
testcase_23 AC 1,382 ms
62,716 KB
testcase_24 AC 1,280 ms
52,964 KB
testcase_25 AC 1,532 ms
63,176 KB
testcase_26 AC 1,645 ms
64,428 KB
testcase_27 AC 88 ms
38,376 KB
testcase_28 AC 88 ms
38,304 KB
testcase_29 AC 76 ms
38,376 KB
testcase_30 AC 856 ms
62,028 KB
testcase_31 AC 805 ms
59,280 KB
testcase_32 AC 49 ms
37,068 KB
testcase_33 AC 49 ms
37,112 KB
testcase_34 AC 49 ms
37,184 KB
testcase_35 AC 48 ms
37,292 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(-1L);
        list.add(Long.MAX_VALUE);
        StringBuilder sb = new StringBuilder();
        while (n-- > 0) {
            if (sc.nextInt() == 1) {
                long v = sc.nextLong();
                int left = 0;
                int right = list.size();
                while (right - left > 1) {
                    int m = (left + right) / 2;
                    if (list.get(m) < v) {
                        left = m;
                    } else {
                        right = m;
                    }
                }
                list.add(right, v);
            } else {
                if (list.size() > k + 1) {
                    sb.append(list.remove(k)).append("\n");
                } else {
                    sb.append("-1\n");
                }
            }
        }
        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