結果
| 問題 |
No.3298 K-th Slime
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-24 21:10:57 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 614 ms / 2,000 ms |
| コード長 | 904 bytes |
| コンパイル時間 | 145 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 21,640 KB |
| 最終ジャッジ日時 | 2025-09-12 01:52:06 |
| 合計ジャッジ時間 | 7,415 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#! /usr/bin/env python3
import heapq
N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
hq1 = []
hq2 = []
for i, a in enumerate(sorted(A)):
if i < K:
heapq.heappush(hq1, -a)
else:
heapq.heappush(hq2, a)
for _ in range(Q):
q = list(map(int, input().split()))
if q[0] == 1:
x = q[1]
if x < -hq1[0] :
y = - heapq.heappop(hq1)
heapq.heappush(hq1, -x)
heapq.heappush(hq2, y)
else:
heapq.heappush(hq2, x)
elif q[0] == 2:
x = q[1]
y = -heapq.heappop(hq1)
if not hq2:
heapq.heappush(hq1, -(x + y))
continue
if x + y <= hq2[0]:
heapq.heappush(hq1, -(x + y))
else:
z = heapq.heappop(hq2)
heapq.heappush(hq1, -z)
heapq.heappush(hq2, x + y)
else:
print(-hq1[0])