結果

問題 No.649 ここでちょっとQK!
ユーザー matsu7874matsu7874
提出日時 2018-02-04 19:55:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,300 ms / 3,000 ms
コード長 779 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 20,476 KB
最終ジャッジ日時 2024-04-16 21:11:15
合計ジャッジ時間 16,277 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 1,300 ms
10,752 KB
testcase_04 AC 905 ms
18,688 KB
testcase_05 AC 759 ms
18,688 KB
testcase_06 AC 756 ms
20,476 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 31 ms
10,752 KB
testcase_11 AC 31 ms
10,752 KB
testcase_12 AC 440 ms
14,080 KB
testcase_13 AC 439 ms
13,952 KB
testcase_14 AC 433 ms
13,952 KB
testcase_15 AC 457 ms
13,952 KB
testcase_16 AC 441 ms
14,208 KB
testcase_17 AC 509 ms
14,592 KB
testcase_18 AC 568 ms
14,848 KB
testcase_19 AC 613 ms
15,232 KB
testcase_20 AC 669 ms
15,488 KB
testcase_21 AC 714 ms
15,744 KB
testcase_22 AC 760 ms
16,128 KB
testcase_23 AC 784 ms
16,384 KB
testcase_24 AC 857 ms
16,896 KB
testcase_25 AC 889 ms
17,152 KB
testcase_26 AC 946 ms
17,280 KB
testcase_27 AC 35 ms
10,752 KB
testcase_28 AC 35 ms
10,880 KB
testcase_29 AC 34 ms
10,752 KB
testcase_30 AC 430 ms
13,824 KB
testcase_31 AC 455 ms
14,208 KB
testcase_32 AC 31 ms
10,752 KB
testcase_33 AC 30 ms
10,752 KB
testcase_34 AC 30 ms
10,880 KB
testcase_35 AC 30 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