結果
問題 | No.2804 Fixer And Ratism |
ユーザー |
|
提出日時 | 2024-11-13 09:09:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 159 ms / 2,000 ms |
コード長 | 1,668 bytes |
コンパイル時間 | 511 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 76,672 KB |
最終ジャッジ日時 | 2024-11-13 09:09:14 |
合計ジャッジ時間 | 7,575 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
import heapqN,Q = map(int,input().split())tot = Ncnt = Nque = []ast = set()for _ in range(Q):qry = list(input().split())if qry[0]=="1":s,r = qry[1:]r = int(r)heapq.heappush(que,(r,s))if cnt>0:cnt -= 1else:while True:r0,s0 = heapq.heappop(que)if s0 not in ast:print(s0)breakelse:if r0>=10000:ast.discard(s0)print(s0)breakelse:r0 += 10000heapq.heappush(que,(r0,s0))elif qry[0]=="2":x = int(qry[1])if cnt>=x:cnt -= xtot -= xelse:d = x-cnttot -= cntcnt = 0outs = []while d>0:r,s = heapq.heappop(que)if s not in ast:tot -= 1d -= 1heapq.heappush(outs,(r,s))else:if r>=10000:r -= 10000tot -= 1ast.discard(s)d -= 1heapq.heappush(outs,(r,s))else:r += 10000heapq.heappush(que,(r,s))while outs:r,s = heapq.heappop(outs)print(s)else:s,x = qry[1:]x = int(x)ast.add(s)tot += xcnt += x