알고리즘/Baekjoon

[Baekjoon] #11047 동전 0

개발생각11 2022. 6. 22. 19:19
반응형

import java.util.Scanner;

//Q) 동전0 #11047
public class Main {


	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(); //동전의 개수
		int k = sc.nextInt(); //가치의 합
		
		int[] coins = new int[n];
		int cnt=0;
		int bigIndex =0;
		
		for(int i=0;i<coins.length;i++){
			coins[i] = sc.nextInt();
		}
	
		while(k!=0){
			for(int i=0;i<coins.length;i++){
				if(coins[i]<=k){
					bigIndex=i;
				}
			}
			k=k-coins[bigIndex];
			cnt++;
		}
		
		System.out.println(cnt);
			
	}
	
}
반응형