結果

問題 No.649 ここでちょっとQK!
ユーザー matsu7874matsu7874
提出日時 2018-02-04 19:51:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 773 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2024-04-16 21:10:18
合計ジャッジ時間 16,357 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 WA -
testcase_03 AC 1,240 ms
10,880 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 757 ms
21,888 KB
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 AC 31 ms
10,752 KB
testcase_34 AC 30 ms
10,752 KB
testcase_35 AC 31 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

Q, K = map(int, input().split())

heap_k_least = []
heap_other = []

size = 0

for i in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        if size < K:
            heapq.heappush(heap_k_least, query[1])
            size += 1
        elif heap_k_least[0] < query[1]:
            heapq.heappush(heap_other, heapq.heappop(heap_k_least))
            heapq.heappush(heap_k_least, query[1])
        else:
            heapq.heappush(heap_other, query[1])
    else:
        if size >= K:
            print(heap_k_least[0])
            if heap_other:
                heap_k_least[0] = heapq.heappop(heap_other)
            else:
                heapq.heappop(heap_k_least)
                size -= 1
        else:
            print(-1)
0