結果

問題 No.649 ここでちょっとQK!
ユーザー H3PO4H3PO4
提出日時 2020-10-27 08:44:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 441 ms / 3,000 ms
コード長 752 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 16,156 KB
最終ジャッジ日時 2023-09-29 03:11:39
合計ジャッジ時間 11,125 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,956 KB
testcase_01 AC 17 ms
8,104 KB
testcase_02 AC 16 ms
7,960 KB
testcase_03 AC 312 ms
8,520 KB
testcase_04 AC 441 ms
16,156 KB
testcase_05 AC 316 ms
16,156 KB
testcase_06 AC 316 ms
16,080 KB
testcase_07 AC 17 ms
8,004 KB
testcase_08 AC 16 ms
8,096 KB
testcase_09 AC 16 ms
8,000 KB
testcase_10 AC 16 ms
8,092 KB
testcase_11 AC 17 ms
8,092 KB
testcase_12 AC 187 ms
11,552 KB
testcase_13 AC 187 ms
11,440 KB
testcase_14 AC 188 ms
11,536 KB
testcase_15 AC 202 ms
11,796 KB
testcase_16 AC 181 ms
11,812 KB
testcase_17 AC 236 ms
12,148 KB
testcase_18 AC 255 ms
12,620 KB
testcase_19 AC 283 ms
12,624 KB
testcase_20 AC 301 ms
13,172 KB
testcase_21 AC 332 ms
13,344 KB
testcase_22 AC 356 ms
13,596 KB
testcase_23 AC 377 ms
14,080 KB
testcase_24 AC 401 ms
14,372 KB
testcase_25 AC 424 ms
14,640 KB
testcase_26 AC 439 ms
14,852 KB
testcase_27 AC 18 ms
7,936 KB
testcase_28 AC 18 ms
8,088 KB
testcase_29 AC 18 ms
7,960 KB
testcase_30 AC 187 ms
11,728 KB
testcase_31 AC 205 ms
11,832 KB
testcase_32 AC 17 ms
7,924 KB
testcase_33 AC 17 ms
7,988 KB
testcase_34 AC 16 ms
8,008 KB
testcase_35 AC 16 ms
8,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys

input = sys.stdin.buffer.readline

Q, K = map(int, input().split())
h_left, h_right = [], []

for _ in range(Q):
    q = tuple(map(int, input().split()))
    if q[0] == 1:
        v = q[1]
        if len(h_left) < K:
            heapq.heappush(h_left, -v)
        elif -h_left[0] >= v:
            x = -heapq.heappushpop(h_left, -v)
            heapq.heappush(h_right, x)
        else:
            heapq.heappush(h_right, v)
    else:
        if len(h_left) < K:
            print(-1)
        else:
            if h_right:
                y = heapq.heappop(h_right)
                x = -heapq.heapreplace(h_left, -y)
            else:
                x = -heapq.heappop(h_left)
            print(x)
    # print(h_left, h_right)
0