동전 0 11047

LJM·2023년 3월 13일
0

백준풀기

목록 보기
137/259

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

시간복잡
K/A
1억/1원

import java.io.*;
public class Main
{
    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]);

        int K = Integer.parseInt(input[1]);

        int[] coin = new int[N];

        for(int i = 0; i < N; ++i)
        {
            coin[i] = Integer.parseInt(br.readLine());
        }

        int copy = K;
        int idx = N-1;
        int ans = 0;
        while(copy > 0 && idx >= 0)
        {
            int temp = copy / coin[idx];
            if(temp > 0)
            {
                ans += temp;
                copy %= coin[idx];
            }
            else {
                idx--;
            }
        }

        System.out.println(ans);
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글