結果

問題 No.1708 Quality of Contest
ユーザー ntuda
提出日時 2025-02-26 21:10:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 709 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 82,232 KB
実行使用メモリ 159,236 KB
最終ジャッジ日時 2025-02-26 21:10:29
合計ジャッジ時間 13,502 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
N,M,X = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
K = int(input())
C = list(map(int,input().split()))
J = [[] for _ in range(M)]
Y = [0] * N
Q1 = []
Q2 = []
solved = set()

for a,b in AB:
    b -= 1
    J[b].append(a)

for c in C:
    if c > 0:
        Y[c - 1] += 1

for i in range(M):
    if J[i]:
        J[i].sort()
        x = J[i].pop()
        heappush(Q1,(-x,i))

ans = 0
tmp = 0
for i in range(N):
    if Q2:
        if Q1:
            if Q1[0][0] - X < Q2[0][0]:
                x, jn = heappop(Q1)
                tmp += -x + X
            else:
                x, jn = heappop(Q2)
                tmp += -x
        else:
            x, jn = heappop(Q2)
            tmp += -x
    else:
        if Q1:
            x, jn = heappop(Q1)
            tmp += -x + X
    if J[jn]:
        heappush(Q2,(-J[jn].pop(),jn))

    ans += tmp * Y[i]

print(ans)
0