結果
| 問題 | No.649 ここでちょっとQK! |
| コンテスト | |
| ユーザー |
qqqq
|
| 提出日時 | 2019-07-23 19:05:59 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 423 ms / 3,000 ms |
| コード長 | 1,055 bytes |
| コンパイル時間 | 97 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 20,352 KB |
| 最終ジャッジ日時 | 2024-06-26 06:35:32 |
| 合計ジャッジ時間 | 8,039 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
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()
qqqq