結果
問題 | No.2957 Combo Deck Builder |
ユーザー |
|
提出日時 | 2024-11-08 22:45:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 708 ms / 1,000 ms |
コード長 | 929 bytes |
コンパイル時間 | 643 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 130,048 KB |
最終ジャッジ日時 | 2024-11-08 22:46:17 |
合計ジャッジ時間 | 20,612 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random input = sys.stdin.readline n = int(input()) a = [list(map(int,input().split())) for i in range(n)] p = [] q = [] ans = 0 t = 0 for c,x,y in a: if c == 0: ans += x t += 1 continue if c == n: ans += y t += 1 continue if x > y: p.append((x-y,c)) ans += y elif x < y: q.append((y-x,c)) ans += x else: ans += x t += 1 t += len(q) h = [] p.sort(key=lambda z:z[1],reverse=True) for i in range(t,n): while p and p[-1][1] <= i: heapq.heappush(h,-p[-1][0]) p.pop() if h: ans -= heapq.heappop(h) q.sort(key=lambda z:z[1]) h = [] for i in reversed(range(t)): while q and q[-1][-1] > i: heapq.heappush(h,-q[-1][0]) q.pop() if h: ans -= heapq.heappop(h) print(ans)