結果

問題 No.1708 Quality of Contest
ユーザー FromBooska
提出日時 2023-03-17 15:13:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 559 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 150,168 KB
最終ジャッジ日時 2024-09-18 09:59:52
合計ジャッジ時間 12,445 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

# ナップザックの変形かと思ったが違うみたい
# ABC116D Various Sushiのようにもできない
# なんらかの貪欲法で並べることが必要
# 与えられたABリストを、初めてのグループであれば+X点として新リスト作成
# ソート、カウント累積和で高速化で総和計算

N, M, X = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])
K = int(input())
C = list(map(int, input().split()))

AB.sort(key = lambda x:x[0], reverse = True)
#print(AB)

genre = set()
AB_adjusted = []
for a, b in AB:
    if b not in genre:
        genre.add(b)
        AB_adjusted.append(a+X)
    else:
        AB_adjusted.append(a)

AB_adjusted.sort(reverse = True)

count = [0]*(N+2)
for c in C:
    count[1] += 1
    count[c+1] -= 1
for i in range(1, N+2):
    count[i] += count[i-1]

#print(AB_adjusted)
#print(count)

ans = 0
for i in range(N):
    ans += AB_adjusted[i]*count[i+1]
print(ans)
0