[백준] 9329 패스트 푸드 상금

알파·2022년 6월 7일
0

Algorithm

목록 보기
6/20

로직 자체는 어렵지 않았는데 아직도 자바 언어로 알고리즘을 푸는데 익숙지 않다고 느끼게 한 문제였다.
상금으로 바꾸기 위한 스티커가 겹치지 않기 때문에, 필요한 스티커들 중 가장 적은 스티커의 갯수만큼 상금을 곱해 더해주면 되는 문제였다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        for (int i = 0; i < T; i++) {
         String[] temp = br.readLine().split(" ");
         int numPrize = Integer.parseInt(temp[0]);
         int numSticker = Integer.parseInt(temp[1]);
         
         int [][] prizes = new int[numPrize][100];
         int [] stickers = new int [numSticker+1];
         
         for (int j = 0; j < numPrize; j++) {
             String[] temp2 = br.readLine().split(" ");
             prizes[j][0] = Integer.parseInt(temp2[0]);
             for (int z = 1; z <= prizes[j][0] + 1; z++) {
                 prizes[j][z] = Integer.parseInt(temp2[z]);
             }
         }
         String[] temp3 = br.readLine().split(" ");
         for (int j = 0; j < numSticker; j++) {
             stickers[j] = Integer.parseInt(temp3[j]);
         }

         int result = 0;
         for (int j = 0; j < numPrize; j++) {
             int min = 987654321;
             for (int z = 1; z <= prizes[j][0]; z++) {
                 if (stickers[prizes[j][z] - 1] < min){
                     min = stickers[prizes[j][z] - 1];
                 }
             }
             result += prizes[j][prizes[j][0] + 1] * min;

         }
         System.out.println(result);
        }
    }
}
profile
I am what I repeatedly do

0개의 댓글