結果
| 問題 |
No.1708 Quality of Contest
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-10-15 22:12:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 916 ms / 2,000 ms |
| コード長 | 931 bytes |
| コンパイル時間 | 170 ms |
| コンパイル使用メモリ | 82,556 KB |
| 実行使用メモリ | 131,048 KB |
| 最終ジャッジ日時 | 2024-09-17 17:34:37 |
| 合計ジャッジ時間 | 14,295 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
from heapq import heappush,heappop
n,m,x = map(int,input().split())
p = [[] for i in range(m)]
for i in range(n):
a,b = map(int,input().split())
p[b-1].append(a)
k = int(input())
C = list(map(int,input().split()))
count = [0]*(n+1)
for c in C:
count[c] += 1
ans = 0
h1 = []
h2 = []
for i in range(m):
if p[i]:
p[i].sort()
heappush(h1,[-p[i].pop(),i])
now = k-count[0]
for i in range(1,n+1):
if h2 == []:
ans += x*now
a,ind = heappop(h1)
ans += (-a)*now
for j in p[ind]:
heappush(h2,-j)
elif h1 == []:
a= -heappop(h2)
ans += a*now
else:
if -h1[0][0]+x >= -h2[0]:
ans += x*now
a,ind = heappop(h1)
ans += (-a)*now
for j in p[ind]:
heappush(h2,-j)
else:
a= -heappop(h2)
ans += a*now
now -= count[i]
print(ans)