結果

問題 No.649 ここでちょっとQK!
ユーザー kakira9618kakira9618
提出日時 2018-02-05 23:21:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 293 ms / 3,000 ms
コード長 842 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,676 KB
実行使用メモリ 87,368 KB
最終ジャッジ日時 2024-04-16 21:13:09
合計ジャッジ時間 6,919 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,736 KB
testcase_01 AC 34 ms
53,248 KB
testcase_02 AC 35 ms
52,864 KB
testcase_03 AC 149 ms
87,368 KB
testcase_04 AC 257 ms
87,136 KB
testcase_05 AC 197 ms
85,412 KB
testcase_06 AC 211 ms
83,540 KB
testcase_07 AC 35 ms
52,608 KB
testcase_08 AC 35 ms
52,864 KB
testcase_09 AC 35 ms
53,376 KB
testcase_10 AC 35 ms
52,352 KB
testcase_11 AC 33 ms
52,224 KB
testcase_12 AC 161 ms
80,756 KB
testcase_13 AC 155 ms
80,356 KB
testcase_14 AC 167 ms
80,676 KB
testcase_15 AC 207 ms
81,620 KB
testcase_16 AC 182 ms
79,868 KB
testcase_17 AC 198 ms
81,236 KB
testcase_18 AC 216 ms
81,540 KB
testcase_19 AC 223 ms
82,176 KB
testcase_20 AC 235 ms
82,812 KB
testcase_21 AC 240 ms
83,976 KB
testcase_22 AC 247 ms
84,144 KB
testcase_23 AC 254 ms
84,112 KB
testcase_24 AC 260 ms
85,248 KB
testcase_25 AC 266 ms
85,528 KB
testcase_26 AC 293 ms
86,672 KB
testcase_27 AC 56 ms
65,792 KB
testcase_28 AC 61 ms
65,664 KB
testcase_29 AC 60 ms
67,456 KB
testcase_30 AC 184 ms
81,272 KB
testcase_31 AC 193 ms
80,104 KB
testcase_32 AC 34 ms
52,592 KB
testcase_33 AC 35 ms
52,736 KB
testcase_34 AC 37 ms
52,736 KB
testcase_35 AC 35 ms
52,864 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