LoginSignup
0
0

More than 1 year has passed since last update.

ABC121 C - Energy Drink Collector を解いた

Posted at

abc121_1.png
abc121_2.png
abc121_3.png
abc121_4.png

貪欲的な感じで 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)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0