結果

問題 No.649 ここでちょっとQK!
ユーザー c-yanc-yan
提出日時 2021-02-15 00:15:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 355 ms / 3,000 ms
コード長 694 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 17,760 KB
最終ジャッジ日時 2023-09-29 18:10:46
合計ジャッジ時間 6,961 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,028 KB
testcase_01 AC 17 ms
8,000 KB
testcase_02 AC 16 ms
8,008 KB
testcase_03 AC 175 ms
14,680 KB
testcase_04 AC 355 ms
15,960 KB
testcase_05 AC 244 ms
15,920 KB
testcase_06 AC 225 ms
17,760 KB
testcase_07 AC 15 ms
8,108 KB
testcase_08 AC 15 ms
8,012 KB
testcase_09 AC 15 ms
8,000 KB
testcase_10 AC 16 ms
8,124 KB
testcase_11 AC 15 ms
8,112 KB
testcase_12 AC 142 ms
12,008 KB
testcase_13 AC 142 ms
12,108 KB
testcase_14 AC 138 ms
12,020 KB
testcase_15 AC 151 ms
12,172 KB
testcase_16 AC 135 ms
12,456 KB
testcase_17 AC 172 ms
12,624 KB
testcase_18 AC 189 ms
13,132 KB
testcase_19 AC 210 ms
13,384 KB
testcase_20 AC 231 ms
13,756 KB
testcase_21 AC 245 ms
14,288 KB
testcase_22 AC 266 ms
14,624 KB
testcase_23 AC 279 ms
14,828 KB
testcase_24 AC 290 ms
15,320 KB
testcase_25 AC 308 ms
15,544 KB
testcase_26 AC 331 ms
16,028 KB
testcase_27 AC 17 ms
8,064 KB
testcase_28 AC 16 ms
7,988 KB
testcase_29 AC 17 ms
8,084 KB
testcase_30 AC 140 ms
12,076 KB
testcase_31 AC 150 ms
12,152 KB
testcase_32 AC 16 ms
8,188 KB
testcase_33 AC 15 ms
8,020 KB
testcase_34 AC 15 ms
8,132 KB
testcase_35 AC 15 ms
8,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from heapq import heappop, heappush

readline = stdin.readline

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

result = []
q0 = []
q1 = []
for _ in range(Q):
    query = readline()
    if query[0] == '1':
        v = int(query[2:])
        if len(q0) < K:
            heappush(q0, -v)
        else:
            if -q0[0] > v:
                heappush(q1, -heappop(q0))
                heappush(q0, -v)
            else:
                heappush(q1, v)
    elif query[0] == '2':
        if len(q0) < K:
            result.append(-1)
        else:
            result.append(-heappop(q0))
            if len(q1) > 0:
                heappush(q0, -heappop(q1))
print(*result, sep='\n')
0