結果

問題 No.649 ここでちょっとQK!
ユーザー vwxyzvwxyz
提出日時 2022-03-19 19:15:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 497 ms / 3,000 ms
コード長 1,022 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 89,548 KB
最終ジャッジ日時 2024-04-15 09:13:10
合計ジャッジ時間 10,405 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,460 KB
testcase_01 AC 40 ms
52,736 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 105 ms
75,912 KB
testcase_04 AC 370 ms
87,112 KB
testcase_05 AC 355 ms
89,320 KB
testcase_06 AC 210 ms
83,900 KB
testcase_07 AC 40 ms
52,608 KB
testcase_08 AC 39 ms
52,480 KB
testcase_09 AC 40 ms
52,992 KB
testcase_10 AC 41 ms
52,480 KB
testcase_11 AC 40 ms
52,480 KB
testcase_12 AC 300 ms
83,544 KB
testcase_13 AC 286 ms
82,684 KB
testcase_14 AC 285 ms
82,912 KB
testcase_15 AC 390 ms
84,412 KB
testcase_16 AC 258 ms
79,804 KB
testcase_17 AC 376 ms
82,396 KB
testcase_18 AC 379 ms
82,808 KB
testcase_19 AC 418 ms
83,588 KB
testcase_20 AC 434 ms
84,288 KB
testcase_21 AC 455 ms
86,144 KB
testcase_22 AC 434 ms
85,640 KB
testcase_23 AC 458 ms
86,652 KB
testcase_24 AC 472 ms
87,316 KB
testcase_25 AC 477 ms
86,804 KB
testcase_26 AC 497 ms
89,548 KB
testcase_27 AC 68 ms
68,352 KB
testcase_28 AC 68 ms
68,352 KB
testcase_29 AC 65 ms
67,072 KB
testcase_30 AC 342 ms
84,288 KB
testcase_31 AC 339 ms
81,376 KB
testcase_32 AC 41 ms
53,648 KB
testcase_33 AC 40 ms
53,656 KB
testcase_34 AC 41 ms
53,188 KB
testcase_35 AC 39 ms
53,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
readline=sys.stdin.readline

Q,K=map(int,readline().split())
queue0,queue1=[],[]
for _ in range(Q):
    data=map(int,readline().split())
    if next(data)==1:
        v=next(data)
        if len(queue0)<K:
            _heappush_max(queue0,v)
        else:
            heappush(queue1,v)
            x=_heappop_max(queue0)
            y=heappop(queue1)
            if x>y:
                x,y=y,x
            _heappush_max(queue0,x)
            heappush(queue1,y)
    else:
        if len(queue0)<K:
            ans=-1
        else:
            ans=_heappop_max(queue0)
            if queue1:
                _heappush_max(queue0,heappop(queue1))
        print(ans)
0