백준 11047번(Java)

박은지·2025년 3월 5일

백준

목록 보기
43/89
post-thumbnail

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
		
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		
		int[] coin = new int[n]; // 동전 가치
		
		for(int i=0; i<n; i++) {
			coin[i] = Integer.parseInt(br.readLine());
		}
		
		int cnt = 0;
		
		for(int i=n-1; i>=0; i--) {
			if(coin[i] <= k) { // 현재 동전의 가치가 k보다 작거나 같으면
				cnt += (k/coin[i]); // 현재 가치의 동전으로 구성할 개수 더하기
				k = k % coin[i];
			}
		}
		System.out.println(cnt);
	}
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글