結果
| 問題 | No.3298 K-th Slime |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-02 00:01:41 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 231 ms / 2,000 ms |
| コード長 | 1,599 bytes |
| 記録 | |
| コンパイル時間 | 403 ms |
| コンパイル使用メモリ | 85,148 KB |
| 実行使用メモリ | 99,740 KB |
| 最終ジャッジ日時 | 2026-03-02 00:01:48 |
| 合計ジャッジ時間 | 4,641 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
## https://yukicoder.me/problems/no/3298
import heapq
def main():
K, K, Q = map(int, input().split())
A = list(map(int, input().split()))
queries = []
for _ in range(Q):
values = tuple(map(int, input().split()))
queries.append(values)
lower_queue = []
upper_queue = []
for a in A:
if len(lower_queue) < K:
heapq.heappush(lower_queue, -a)
else:
if -lower_queue[0] > a:
old_a = heapq.heappop(lower_queue)
old_a = -old_a
heapq.heappush(lower_queue, -a)
heapq.heappush(upper_queue, old_a)
else:
heapq.heappush(upper_queue, a)
for values in queries:
if values[0] == 1:
_, a = values
if -lower_queue[0] > a:
old_a = heapq.heappop(lower_queue)
old_a = -old_a
heapq.heappush(lower_queue, -a)
heapq.heappush(upper_queue, old_a)
else:
heapq.heappush(upper_queue, a)
elif values[0] == 2:
_, y = values
a = heapq.heappop(lower_queue)
a = -a
b = a + y
if len(upper_queue) == 0 or upper_queue[0] >= b:
heapq.heappush(lower_queue, -b)
else:
x = heapq.heappop(upper_queue)
heapq.heappush(lower_queue, -x)
heapq.heappush(upper_queue, b)
else:
print(-lower_queue[0])
if __name__ == "__main__":
main()