ABC121 C - Energy Drink Collector を解いた
3768 ワード
貪欲的な感じで Ai,Bi のリストをソートし、
最安値のモノから買い占めればよろしいのでは?以下で通った。
EnergyDrinkCollector.py
N,M = map(int,input().split())
lis = []
for _ in range(N):
a,b = map(int,input().split())
lis.append([a,b])
lis = sorted(lis,key=lambda t:t[0])
score = 0
for a,b in lis:
if M == b:
score += a*b
break
elif M-b > 0:
M -= b
score += a*b
else:
score += a*M
break
print(score)
Author And Source
この問題について(ABC121 C - Energy Drink Collector を解いた), 我々は、より多くの情報をここで見つけました https://qiita.com/AKpirion/items/7958e9f34360564c5958著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .