結果

問題 No.649 ここでちょっとQK!
ユーザー kakira9618kakira9618
提出日時 2018-02-05 23:17:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 838 ms / 3,000 ms
コード長 842 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 24,064 KB
最終ジャッジ日時 2024-04-16 21:14:15
合計ジャッジ時間 14,032 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 603 ms
24,064 KB
testcase_04 AC 838 ms
18,816 KB
testcase_05 AC 705 ms
18,816 KB
testcase_06 AC 681 ms
20,352 KB
testcase_07 AC 28 ms
10,752 KB
testcase_08 AC 26 ms
10,880 KB
testcase_09 AC 27 ms
10,880 KB
testcase_10 AC 26 ms
10,880 KB
testcase_11 AC 27 ms
10,752 KB
testcase_12 AC 370 ms
15,360 KB
testcase_13 AC 363 ms
15,360 KB
testcase_14 AC 372 ms
15,360 KB
testcase_15 AC 375 ms
15,488 KB
testcase_16 AC 367 ms
14,976 KB
testcase_17 AC 443 ms
15,612 KB
testcase_18 AC 482 ms
16,128 KB
testcase_19 AC 521 ms
16,640 KB
testcase_20 AC 573 ms
16,980 KB
testcase_21 AC 595 ms
17,408 KB
testcase_22 AC 631 ms
18,048 KB
testcase_23 AC 666 ms
18,304 KB
testcase_24 AC 707 ms
18,816 KB
testcase_25 AC 740 ms
19,328 KB
testcase_26 AC 775 ms
19,712 KB
testcase_27 AC 30 ms
10,752 KB
testcase_28 AC 29 ms
10,752 KB
testcase_29 AC 29 ms
10,752 KB
testcase_30 AC 348 ms
14,976 KB
testcase_31 AC 390 ms
15,104 KB
testcase_32 AC 29 ms
10,752 KB
testcase_33 AC 28 ms
10,880 KB
testcase_34 AC 26 ms
10,752 KB
testcase_35 AC 26 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

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

heap_k_least = []
heap_other = []

size = 0

ans = []
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:
            ans.append(-heap_k_least[0])
            if heap_other:
                heap_k_least[0] = -heapq.heappop(heap_other)
            else:
                heapq.heappop(heap_k_least)
                size -= 1
        else:
            ans.append(-1)
            
print ('\n'.join(map(str,ans)))
0