카테고리 없음

백준 11047 실버 4 - 동전 0

_hanbxx_ 2024. 3. 18. 16:03
728x90

https://www.acmicpc.net/problem/11047

 

11047번: 동전 0

첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) 둘째 줄부터 N개의 줄에 동전의 가치 Ai가 오름차순으로 주어진다. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2인 경우에 Ai는 Ai-1의 배수)

www.acmicpc.net

 

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

// The main method must be in a class named "Main".
class Main {
    public static int N,K;
    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());
        List<Integer> li = new ArrayList<>();
        
        for (int i = 0; i < N; i++) {
            li.add(Integer.parseInt(br.readLine()));
        }
        int count = 0;
        Collections.sort(li,Collections.reverseOrder());

        while (K != 0) {
            for (int a : li) {
                if (a <= K) {
                    int left = K / a;
                    count += left;
                    K -= left * a;
                }
            }
        
        }

        
        System.out.println(count);
    }
}
728x90