public class Main
{// 탐욕적 알고리즘으로 거스름돈 최소 동전으로 주기
// but 12원 이런 동전 나오면 쓸 수 없음.
public static int func(int m, int[] d, int n)
{ // 도전 종류, 동전 값, 거스름돈
int count = 0;
int i = 0;
while (n > 0 && i<m)
{
count += n/d[i];
n = n % d[i];
i++;
}
return count;
}
public static void main(String[] args)
{
int m = 5;
int[] d = {500, 100, 50, 10, 1};
int n = 654;
System.out.println(func(m, d, n));
}
}