[Algorithm log] 그리디#13 백준 11407

n,k = map(int,input().split())
result = 0
coin = []
rest = k

for i in range(n) :
    coin.append(int(input()))
    
coin.sort(reverse=True) 

for i in range(len(coin)) :
    if coin[i] <= rest :
        m = rest//coin[i]
        result+=m
        rest = rest%coin[i]
        if rest==0 :
            break
    else :
        continue
        
    
print(result)

좋은 웹페이지 즐겨찾기