Algorithm Problems

[백준] [Python] 11047번 동전0 - Greedy

WakaraNai 2021. 5. 25. 03:08
728x90
반응형

https://www.acmicpc.net/submit/11047

 

 

Python

import sys
n, money = map(int, sys.stdin.readline().split())
coin = [int(sys.stdin.readline().rstrip()) for _ in range(n)]
idx = -1
cnt = 0
while money > 0:
    while coin[idx] <= money:
        x = money//coin[idx]
        money -= coin[idx]*x
        cnt += x
    idx -= 1
print(cnt)
728x90
반응형