結果

問題 No.649 ここでちょっとQK!
コンテスト
ユーザー cologne
提出日時 2025-12-18 16:23:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 636 ms / 3,000 ms
コード長 1,048 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 325 ms
コンパイル使用メモリ 82,608 KB
実行使用メモリ 96,692 KB
最終ジャッジ日時 2025-12-18 16:23:39
合計ジャッジ時間 11,292 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
from typing import Generator, List, Tuple
import heapq


def input(): return sys.stdin.readline().rstrip('\n')


def main():
    q, k = map(int, input().split())

    topk = []
    bot = []
    for _ in range(q):
        qry = input()
        if qry == '2':
            if len(topk) < k:
                yield -1
            else:
                yield -topk[0]
                heapq.heappop(topk)
                if bot:
                    el = heapq.heappop(bot)
                    heapq.heappush(topk, -el)
        else:
            _, v = map(int, qry.split())
            heapq.heappush(topk, -v)
            if len(topk) > k:
                el = -heapq.heappop(topk)
                heapq.heappush(bot, el)


if __name__ == '__main__':
    ret = main()


    def out(x):
        if isinstance(x, List) or isinstance(x, Tuple):
            print(*x)
        else:
            print(x)


    if ret is None:
        pass
    elif isinstance(ret, Generator):
        for val in ret:
            out(val)
    else:
        out(ret)
0