[AtCoder]ABC127 D-Integer Cards

【問題】

ERROR: The request could not be satisfied
問題キャプチャ

【方針】\(C_j\)を大きい順に\(B_j\)個並べたリストを作る。このリストと\(A\)を結合し、大きい方から順に\(N\)個取れば良い。

【解答】

#input
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = []
for i in range(m):
    b, c = map(int, input().split())
    d.append([b, c])

#output
d = sorted(d, key = lambda x:x[1], reverse = True)

counter = 0
e = []
for item in d:
    counter += item[0]
    e+= [item[1]]*item[0]
    if counter >= n:
        break
a += e
a = sorted(a, reverse = True)
print(sum(a[:n]))

【提出結果】

ERROR: The request could not be satisfied

遅いと思ったけれどPythonの中ではなかなか早かったようだ。

コメント

タイトルとURLをコピーしました