

동전의 사용 최소 개수를 구하는 문제이므로 그리디 알고리즘을 사용해 각 단계마다 사용할 수 있는 가장 최대 금액의 동전을 선택하면 전체 답이 구해진다.
풀이과정은 다음과 같다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N, K;
static int[] worth;
static int min = 0;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
worth = new int[N];
for (int i = 0; i < N; i++) {
worth[i] = Integer.parseInt(br.readLine());
}
min();
System.out.println(min);
}
static void min() {
for (int i = N - 1; i >= 0; i--) {
if (worth[i] <= K) {
min += (K / worth[i]);
K = K % worth[i];
}
}
}
}
