結果

問題 No.1708 Quality of Contest
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-10-15 21:47:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 684 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 126,752 KB
最終ジャッジ日時 2023-10-17 20:12:53
合計ジャッジ時間 13,088 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,488 KB
testcase_01 AC 38 ms
53,488 KB
testcase_02 AC 39 ms
53,488 KB
testcase_03 AC 127 ms
77,388 KB
testcase_04 AC 128 ms
77,272 KB
testcase_05 AC 136 ms
77,332 KB
testcase_06 AC 117 ms
77,168 KB
testcase_07 AC 113 ms
77,116 KB
testcase_08 AC 40 ms
53,488 KB
testcase_09 AC 418 ms
121,588 KB
testcase_10 AC 569 ms
120,616 KB
testcase_11 AC 684 ms
119,220 KB
testcase_12 AC 658 ms
121,232 KB
testcase_13 AC 672 ms
119,032 KB
testcase_14 AC 655 ms
121,348 KB
testcase_15 AC 588 ms
121,556 KB
testcase_16 AC 613 ms
122,036 KB
testcase_17 AC 680 ms
126,752 KB
testcase_18 AC 680 ms
126,604 KB
testcase_19 AC 650 ms
120,476 KB
testcase_20 AC 673 ms
121,680 KB
testcase_21 AC 626 ms
121,564 KB
testcase_22 AC 605 ms
119,844 KB
testcase_23 AC 611 ms
120,296 KB
testcase_24 AC 596 ms
119,088 KB
testcase_25 AC 623 ms
126,036 KB
権限があれば一括ダウンロードができます

ソースコード

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