結果

問題 No.649 ここでちょっとQK!
ユーザー qqqqqqqq
提出日時 2019-07-23 19:05:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 334 ms / 3,000 ms
コード長 1,055 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 17,696 KB
最終ジャッジ日時 2023-09-08 13:22:32
合計ジャッジ時間 7,190 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,916 KB
testcase_01 AC 16 ms
8,020 KB
testcase_02 AC 16 ms
8,004 KB
testcase_03 AC 127 ms
14,624 KB
testcase_04 AC 334 ms
16,128 KB
testcase_05 AC 229 ms
15,904 KB
testcase_06 AC 213 ms
17,696 KB
testcase_07 AC 16 ms
8,112 KB
testcase_08 AC 16 ms
7,932 KB
testcase_09 AC 16 ms
7,984 KB
testcase_10 AC 16 ms
8,088 KB
testcase_11 AC 16 ms
8,040 KB
testcase_12 AC 128 ms
12,116 KB
testcase_13 AC 129 ms
12,152 KB
testcase_14 AC 129 ms
12,168 KB
testcase_15 AC 142 ms
12,168 KB
testcase_16 AC 128 ms
12,292 KB
testcase_17 AC 167 ms
12,632 KB
testcase_18 AC 181 ms
12,976 KB
testcase_19 AC 203 ms
13,364 KB
testcase_20 AC 218 ms
13,832 KB
testcase_21 AC 234 ms
14,136 KB
testcase_22 AC 248 ms
14,600 KB
testcase_23 AC 268 ms
15,032 KB
testcase_24 AC 282 ms
15,160 KB
testcase_25 AC 300 ms
15,588 KB
testcase_26 AC 316 ms
16,004 KB
testcase_27 AC 18 ms
8,112 KB
testcase_28 AC 17 ms
7,988 KB
testcase_29 AC 17 ms
7,976 KB
testcase_30 AC 126 ms
12,120 KB
testcase_31 AC 140 ms
12,180 KB
testcase_32 AC 17 ms
7,940 KB
testcase_33 AC 16 ms
8,004 KB
testcase_34 AC 18 ms
7,972 KB
testcase_35 AC 17 ms
7,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import heappop, heappush

def main():
    q, k = map(int, input().split())
    ans = []
    # 下からk個をmax_heap
    small = []
    # それ以外をmin_heap
    large = []
    for i in range(q):
        s = input()
        if len(s) != 2:
            _, v = map(int, s.split())
            # まだk個無い時
            if len(small) < k:
                heappush(small, -v)
            else:
                if -small[0] <= v:
                    heappush(large, v)
                else:
                    a = -heappop(small)
                    heappush(small, -v)
                    heappush(large, a)
        else:
            if len(small) < k:
                ans.append(-1)
#                print(-1)
            else:
                a = -heappop(small)
                ans.append(a)
#                print(a)
                if len(large):
                    b = heappop(large)
                    heappush(small, -b)
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()
0