Notice
Recent Posts
Recent Comments
Link
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
Archives
Today
Total
관리 메뉴

Devvy-Is-Free

[Python] softeer.ai 금고털이 본문

Programming/Algorithm

[Python] softeer.ai 금고털이

Devvy 2022. 10. 3. 02:16

import sys
input = sys.stdin.readline

W, N = map(int, input().split())
stone = []

for _ in range(N):
    mp = list(map(int, input().split()))
    stone.append(mp)

stone.sort(key = lambda x : -x[1])

price = 0

for m, p in stone:
    if m <= W:
        W -= m
        price += m * p
    else:
        price += W * p
        break

print(price)