Playground/자바문제집

[백준] 1049번

미숫가루설탕많이 2023. 5. 23. 00:01

1. 세트와 낱개를 구매하는 경우

2. 세트로만 구매하는 경우

3. 낱개로만 구매하는 경우

 

이 3가지 경우의 수 중에서 가장 작은 수를 구하는 게 포인트이다.

 

 

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 M = Integer.parseInt(st.nextToken());    // 기타줄 브랜드
        int packPrice = 1000;  // 패키지 최소 가격
        int onePrice = 1000;   // 낱개 최소 가격

        for (int i = 0; i < M; i++) {
            st = new StringTokenizer(br.readLine());

            packPrice = Math.min(packPrice, Integer.parseInt(st.nextToken()));
            onePrice = Math.min(onePrice, Integer.parseInt(st.nextToken()));
        }

        int answer = ((N / 6) * packPrice) + ((N % 6) * onePrice);  // 세트와 낱개를 나눠서 구매하는 경우
        answer = Math.min(answer, ((N / 6) + 1) * packPrice);   // 세트만 구매하는 경우
        answer = Math.min(answer, N * onePrice);    // 낱개로만 구매하는 경우
        
        System.out.println(answer);
    }
}

'Playground > 자바문제집' 카테고리의 다른 글

[백준] 1764번  (0) 2023.06.16
[백준] 5430번  (2) 2023.06.09
[백준] 14469번  (0) 2023.05.22
[백준] 11724번  (2) 2023.05.21
[백준] 2667번  (0) 2023.05.18