結果

問題 No.649 ここでちょっとQK!
ユーザー anagohirame
提出日時 2020-09-04 12:05:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 3,000 ms
コード長 484 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 85,528 KB
最終ジャッジ日時 2024-11-25 06:39:05
合計ジャッジ時間 7,677 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

n, k = map(int, input().split())
q1, q2 = [], []

def add(x):
	heappush(q1, -x)
	if len(q1) > k:
		tmp = heappop(q1)
		heappush(q2, -tmp)
	return

def remove():
	if len(q1) < k:
		return -1
	else:
		res = heappop(q1)
		if q2:
			nxt = heappop(q2)
			heappush(q1, -nxt)
		return -res

for _ in range(n):
	t = input().split()
	if len(t) == 2:
		add(int(t[1]))
	else:
		print(remove())
0