[그리디] 백준 11047 동전0 JAVAAlgorithm2024. 4. 20. 14:27
Table of Contents
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);
}
}
'Algorithm' 카테고리의 다른 글
| [구현] 백준 1205 등수구하기 JAVA (0) | 2024.04.27 |
|---|---|
| [완전탐색] 백준 2529 부등호 JAVA (0) | 2024.04.20 |
| [구현] 백준 8979 올림픽 JAVA (1) | 2024.04.19 |
| [완전탐색] 백준 1182 부분수열의 합 JAVA (전위순회) (0) | 2024.04.18 |
| [DFS] 백준 11403 경로찾기 JAVA (1) | 2024.04.18 |