結果

問題 No.3298 K-th Slime
ユーザー sakasama
提出日時 2025-10-05 14:41:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 460 ms / 2,000 ms
コード長 755 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 92,060 KB
最終ジャッジ日時 2025-10-05 14:41:18
合計ジャッジ時間 7,747 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def solve():
    n,k,q = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    
    small = [-a[i] for i in range(k)]
    heapq.heapify(small)
    large = a[k:]
    heapq.heapify(large)

    for _ in range(q):
        query = list(map(int, input().split()))
        if query[0] == 1:
            heapq.heappush(small, -query[1])
            kth = -heapq.heappop(small)
            heapq.heappush(large, kth)
        elif query[0] == 2:
            old_kth = -heapq.heappop(small)
            heapq.heappush(large, old_kth + query[1])
            new_kth = heapq.heappop(large)
            heapq.heappush(small, -new_kth)
        else:
            print(-small[0])
        
if __name__ == "__main__":
    solve()
0