結果

問題 No.1708 Quality of Contest
ユーザー SPD_9X2
提出日時 2021-10-15 21:47:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 599 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 127,044 KB
最終ジャッジ日時 2024-09-17 17:24:26
合計ジャッジ時間 11,444 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

"""

import sys
from sys import stdin
import heapq

N,M,X = map(int,stdin.readline().split())

AB = []

picked = [False] * (M+1)

qa = []
qb = []

for i in range(N):

    A,B = map(int,stdin.readline().split())
    heapq.heappush( qa , (-A,B) )

K = int(stdin.readline())
C = list(map(int,stdin.readline().split()))
ans = 0

RC = [0] * N
for i in C:
    if i != 0:
        RC[i-1] += 1
for i in range(N-1,0,-1):
    RC[i-1] += RC[i]

#print (RC)

for i in range(N):

    while len(qa) > 0 and picked[qa[0][1]]:
        A,B = heapq.heappop(qa)
        heapq.heappush(qb,(A,B))

    if len(qb) == 0:
        A,B = heapq.heappop(qa)
        A *= -1
        ans += (A+X) * RC[i]
        picked[B] = True
    elif len(qa) == 0:
        A,B = heapq.heappop(qb)
        A *= -1
        ans += (A) * RC[i]
    elif -1 * qa[0][0] + X > -1*qb[0][0]:
        A,B = heapq.heappop(qa)
        A *= -1
        ans += (A+X) * RC[i]
        picked[B] = True
    else:
        A,B = heapq.heappop(qb)
        A *= -1
        ans += (A) * RC[i]

print (ans)
0