結果

問題 No.1708 Quality of Contest
ユーザー syunsukesyunsuke
提出日時 2021-11-22 18:20:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 832 ms / 2,000 ms
コード長 1,097 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 152,180 KB
最終ジャッジ日時 2023-09-06 11:45:36
合計ジャッジ時間 18,179 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,080 KB
testcase_01 AC 73 ms
71,400 KB
testcase_02 AC 72 ms
71,300 KB
testcase_03 AC 168 ms
78,936 KB
testcase_04 AC 180 ms
79,336 KB
testcase_05 AC 177 ms
79,532 KB
testcase_06 AC 143 ms
78,532 KB
testcase_07 AC 151 ms
78,584 KB
testcase_08 AC 73 ms
71,340 KB
testcase_09 AC 518 ms
146,704 KB
testcase_10 AC 718 ms
143,932 KB
testcase_11 AC 818 ms
145,620 KB
testcase_12 AC 832 ms
145,620 KB
testcase_13 AC 778 ms
137,800 KB
testcase_14 AC 752 ms
147,236 KB
testcase_15 AC 735 ms
147,124 KB
testcase_16 AC 765 ms
151,808 KB
testcase_17 AC 773 ms
141,876 KB
testcase_18 AC 773 ms
139,452 KB
testcase_19 AC 809 ms
146,644 KB
testcase_20 AC 801 ms
139,772 KB
testcase_21 AC 794 ms
149,008 KB
testcase_22 AC 752 ms
146,060 KB
testcase_23 AC 756 ms
152,180 KB
testcase_24 AC 720 ms
143,740 KB
testcase_25 AC 724 ms
143,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,X = map(int,input().split())
    
import heapq
A = []
B = []

heapq.heapify(A)
heapq.heapify(B)

for i in range(N):
    a,b = map(int,input().split())
    heapq.heappush(B,(-a,b))
    
#print(B)
S = set()
ans = []
NOW = 0
while len(A) + len(B):
    
    while B and B[0][1] in S:
        b = heapq.heappop(B)
        heapq.heappush(A,b)
    #print(S,A,B)
    if len(B):
        b = B[0][0]
        if len(A):
            a = A[0][0]
            if -a < -b+X:
                b = heapq.heappop(B)
                ans.append(NOW + X -b[0])
                NOW = ans[-1]
                S.add(b[1])
            else:
                a = heapq.heappop(A)
                ans.append(NOW - a[0])
                NOW = ans[-1]
        else:
            b = heapq.heappop(B)
            ans.append(NOW + X -b[0])
            NOW = ans[-1]
            S.add(b[1])
    else:
        a = heapq.heappop(A)
        ans.append(NOW - a[0])
        NOW = ans[-1]
#print(ans)

ANS = 0
K = int(input())
C = list(map(int,input().split()))
for i in range(K):
    if C[i] > 0:
        ANS += ans[C[i]-1]
print(ANS)
0