結果

問題 No.649 ここでちょっとQK!
ユーザー denderaKawazudenderaKawazu
提出日時 2018-02-10 15:28:09
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,926 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 79,956 KB
実行使用メモリ 77,660 KB
最終ジャッジ日時 2024-04-21 14:51:34
合計ジャッジ時間 33,353 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 151 ms
41,444 KB
testcase_02 WA -
testcase_03 AC 849 ms
52,856 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 150 ms
41,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Comparator;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int q = in.nextInt();
            int k = in.nextInt();
            PriorityQueue<Long> maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
            PriorityQueue<Long> minHeap = new PriorityQueue<>(Comparator.naturalOrder());

            for (int i = 0; i < q; i++) {
                int qn = in.nextInt();
                if (qn == 1) {
                    long next = in.nextLong();
                    if (maxHeap.size() < k) {
                        maxHeap.add(next);
                    } else {
                        if (next < maxHeap.peek()) {
                            minHeap.add(maxHeap.poll());
                            maxHeap.add(next);
                        } else {
                            minHeap.add(next);
                        }
                    }
                } else {
                    if (maxHeap.size() < k) {
                        out.println(-1);
                    } else {
                        out.println();
                        out.println(maxHeap.poll());
                        if (minHeap.size() > 0) maxHeap.add(minHeap.poll());
                    }
                }
            }
        }

    }
}

0