結果

問題 No.1708 Quality of Contest
ユーザー gr1msl3ygr1msl3y
提出日時 2021-10-15 22:02:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 950 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 149,260 KB
最終ジャッジ日時 2024-09-17 17:30:43
合計ジャッジ時間 17,327 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
import heapq as hq
N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
K = int(input())
C = list(map(int, input().split()))
D = Counter(C)

INF = 10**9
qual = 0
ct = 0
set1 = [(INF, 0)]
set2 = [(INF, 0)]
for a, b in A:
    hq.heappush(set2, (-a, b))
S = set()
ans = 0
for i in range(1, N+1):
    while set2[0][1] in S:
        a = hq.heappop(set2)
        hq.heappush(set1, a)
    v = -set1[0][0]
    w = -set2[0][0]
    if v <= w+X:
        qual += w
        ct += 1
        S.add(set2[0][1])
        hq.heappop(set2)
    else:
        qual += v
        hq.heappop(set1)
    ans += D[i]*(qual+ct*X)

print(ans)
0