結果

問題 No.3298 K-th Slime
ユーザー Basin-Bug
提出日時 2025-10-05 14:21:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 91,868 KB
最終ジャッジ日時 2025-10-05 14:21:40
合計ジャッジ時間 6,504 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import bisect
N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

ftK = A[: K]
atK = A[K:]
heapq.heapify(atK)

for i in range(Q):
  query = list(map(int, input().split()))
  if query[0] == 1:
    if query[1] >= ftK[-1]:
      heapq.heappush(atK, query[1])
    else:
      heapq.heappush(atK, ftK.pop())
      bisect.insort_left(ftK, query[1])
  
  elif query[0] == 2:
    slim = ftK.pop() + query[1]
    if len(atK) >= 1:
      target = heapq.heappop(atK)

      if slim <= target:
        ftK.append(slim)
        heapq.heappush(atK, target)
      else:
        ftK.append(target)
        heapq.heappush(atK, slim)
    else:
        ftK.append(slim)
  
  else:
    print(ftK[-1])      
    
  
0