Algorithm
[그리디] 백준 11047 동전0 JAVA
EllaCoo
2024. 4. 20. 14:27
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class G_9_11047 {
// [그리디] 백준 11047 동전0 JAVA
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int N = Integer.parseInt(input[0]); //1 ≤ N ≤ 10
int K = Integer.parseInt(input[1]); //1 ≤ K ≤ 100,000,000
int[] coin = new int[N];
for (int i = 0 ; i < N ; i++) {
coin[i] = Integer.parseInt(br.readLine());
}
int cnt = 0;
int restBill = K;
for (int i = N-1 ; i >= 0 ; i--) {
if (coin[i] <= restBill) {
cnt += restBill / coin[i];
restBill %= coin[i];
}
}
System.out.println(cnt);
}
}