結果

問題 No.2957 Combo Deck Builder
ユーザー LyricalMaestro
提出日時 2025-01-19 01:37:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,361 bytes
コンパイル時間 1,956 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 198,184 KB
最終ジャッジ日時 2025-01-19 01:38:43
合計ジャッジ時間 34,745 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 28 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2957

import heapq
from collections import deque

def main():
    N = int(input())
    cxy = []
    for _ in range(N):
        c, x, y = map(int, input().split())
        cxy.append((c, x, y))

    c_map = {}
    queue = []
    for i in range(N):
        c, x, y = cxy[i]
        d = x - y
        heapq.heappush(queue, (d, i))
        if c not in c_map:
            c_map[c] = []
        c_map[c].append(i)
    
    used = [False] * N
    answer = 0
    for _, _,y in cxy:
        answer += y

    q = deque()    
    print(answer)
    for c in range(N):
        if c in c_map:
            for j in c_map[c]:
                _, x, y = cxy[j]
                if not used[j]:
                    used[j] = True
                    q.append(x - y)
        
        while len(queue) > 0 and used[queue[0][1]]:
            heapq.heappop(queue)

        if len(queue) > 0:
            if queue[0][0] < 0:
                _, j = heapq.heappop(queue)
                used[j] = True
            elif len(q) > 0:
                d = q.popleft()
                answer += d
            else:
                _, j = heapq.heappop(queue)
                used[j] = True
        else:
            d = q.popleft()
            answer += d
        print(c, answer)
    print(answer)


        











if __name__ == "__main__":
    main()
0