結果

問題 No.1708 Quality of Contest
ユーザー LyricalMaestro
提出日時 2025-03-01 03:53:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 82,904 KB
実行使用メモリ 150,952 KB
最終ジャッジ日時 2025-03-01 03:53:18
合計ジャッジ時間 9,545 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1708

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

    # ジャンル別に
    b_array_map = {}
    for a, b in ab:
        if b not in b_array_map:
            b_array_map[b] = [a]
        else:
            b_array_map[b].append(a)

    array = []    
    for values in b_array_map.values():
        values.sort(reverse=True)
        for j in range(len(values)):
            if j == 0:
                array.append(values[j] + X)
            else:
                array.append(values[j])

    array.sort(reverse=True)

    cum_array = [0] * (N + 1)
    cums = 0
    for i in range(N):
        cums += array[i]
        cum_array[i + 1] = cums

    answer =0
    for c in C:
        answer += cum_array[c]
    print(answer)















if __name__ == "__main__":
    main()
0