結果

問題 No.649 ここでちょっとQK!
ユーザー htensai
提出日時 2019-12-12 12:14:37
言語 Java
(openjdk 23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,194 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 79,380 KB
実行使用メモリ 75,484 KB
最終ジャッジ日時 2024-06-24 22:11:05
合計ジャッジ時間 41,611 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Long> list = new ArrayList<>();
        list.add(0L);
        list.add(Long.MAX_VALUE);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            if (x == 1) {
                long y = sc.nextLong();
                int left = 0;
                int right = list.size() - 1;
                while (right - left > 1) {
                    int m = (left + right) / 2;
                    if (list.get(m) <= y) {
                        left = m;
                    } else {
                        right = m;
                    }
                }
                list.add(right, y);
            } else {
                long ans;
                if (list.size() < k + 2) {
                    ans = -1;
                } else {
                    ans = list.remove(k);
                }
                sb.append(ans).append("\n");
            }
        }
       System.out.print(sb);
    }
}
0