結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2022-03-19 19:12:23 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 930 ms / 3,000 ms |
| コード長 | 1,022 bytes |
| コンパイル時間 | 266 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 21,760 KB |
| 最終ジャッジ日時 | 2024-10-05 02:10:30 |
| 合計ジャッジ時間 | 14,456 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
import heapq
import sys
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
if heap and item < heap[0]:
item, heap[0] = heap[0], item
heapq._siftup_max(heap, 0)
return item
readline=sys.stdin.readline
Q,K=map(int,readline().split())
queue0,queue1=[],[]
for _ in range(Q):
data=map(int,readline().split())
if next(data)==1:
v=next(data)
if len(queue0)<K:
_heappush_max(queue0,v)
else:
heappush(queue1,v)
x=_heappop_max(queue0)
y=heappop(queue1)
if x>y:
x,y=y,x
_heappush_max(queue0,x)
heappush(queue1,y)
else:
if len(queue0)<K:
ans=-1
else:
ans=_heappop_max(queue0)
if queue1:
_heappush_max(queue0,heappop(queue1))
print(ans)
vwxyz