結果

問題 No.649 ここでちょっとQK!
ユーザー Mr.FukuMr.Fuku
提出日時 2018-08-01 17:45:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 802 ms / 3,000 ms
コード長 678 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 11,900 KB
実行使用メモリ 26,372 KB
最終ジャッジ日時 2023-10-19 20:44:41
合計ジャッジ時間 13,846 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,248 KB
testcase_01 AC 33 ms
10,248 KB
testcase_02 AC 29 ms
10,248 KB
testcase_03 AC 589 ms
26,372 KB
testcase_04 AC 802 ms
18,036 KB
testcase_05 AC 664 ms
17,932 KB
testcase_06 AC 651 ms
19,740 KB
testcase_07 AC 30 ms
10,252 KB
testcase_08 AC 29 ms
10,252 KB
testcase_09 AC 31 ms
10,252 KB
testcase_10 AC 30 ms
10,252 KB
testcase_11 AC 30 ms
10,252 KB
testcase_12 AC 353 ms
14,804 KB
testcase_13 AC 360 ms
14,820 KB
testcase_14 AC 359 ms
14,804 KB
testcase_15 AC 374 ms
14,980 KB
testcase_16 AC 359 ms
14,652 KB
testcase_17 AC 426 ms
15,200 KB
testcase_18 AC 469 ms
15,604 KB
testcase_19 AC 513 ms
16,080 KB
testcase_20 AC 555 ms
16,524 KB
testcase_21 AC 588 ms
16,844 KB
testcase_22 AC 633 ms
17,424 KB
testcase_23 AC 665 ms
17,892 KB
testcase_24 AC 701 ms
18,256 KB
testcase_25 AC 734 ms
18,772 KB
testcase_26 AC 787 ms
19,504 KB
testcase_27 AC 33 ms
10,288 KB
testcase_28 AC 33 ms
10,288 KB
testcase_29 AC 34 ms
10,284 KB
testcase_30 AC 346 ms
14,528 KB
testcase_31 AC 379 ms
14,444 KB
testcase_32 AC 29 ms
10,252 KB
testcase_33 AC 30 ms
10,252 KB
testcase_34 AC 30 ms
10,252 KB
testcase_35 AC 29 ms
10,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

q,k = map(int,input().split())
low,high,ans = [],[],[]
size = 0

for i in range(q):
    s = list(map(int,input().split()))
    if s[0]==1:
        if size<k:
            heapq.heappush(low,-s[1])
            size+=1
        elif -low[0]>s[1]:
            heapq.heappush(high,-heapq.heappop(low))
            heapq.heappush(low,-s[1])
        else:
            heapq.heappush(high,s[1])
    else:
        if size==k:
            ans.append(-low[0])
            if high:
                low[0] = -heapq.heappop(high)
            else:
                heapq.heappop(low)
                size-=1
        else:
            ans.append(-1)

print("\n".join(map(str,ans)))
0