본문 바로가기
TIL🔥/코딩테스트

[항해99클럽] Java 비기너_Day 14 브실이의 입시전략

by hk713 2025. 4. 17.

오늘의 문제 >> https://www.acmicpc.net/problem/29723

 

[ 생각 흐름 ]

일단 과목이랑 점수는 Map에 저장해놓고..

공개과목은 Set으로 담기..

그리고 공개 과목 점수랑 비공개 과목 점수를 따로 관리해야될 것 같음

그래야 최소, 최대 점수를 구하니깐..!

 

[ JAVA ] 

import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        sc.nextLine();

        Map<String, Integer> subjectMap = new HashMap<>();
        for (int i=0; i<N; i++){
            String[] input = sc.nextLine().split(" ");
            subjectMap.put(input[0], Integer.parseInt(input[1]));
        }

        Set<String> openSubjects = new HashSet<>();
        for (int i=0; i<K; i++){
            openSubjects.add(sc.nextLine());
        }

        int openSum = 0;
        List<Integer> restScores = new ArrayList<>();

        for (Map.Entry<String, Integer> entry:subjectMap.entrySet()){
            if(openSubjects.contains(entry.getKey())){
                openSum += entry.getValue();
            }else{
                restScores.add(entry.getValue());
            }
        }
        
        Collections.sort(restScores);
        int minScore = openSum;
        for (int i=0; i<M-K; i++){
            minScore += restScores.get(i);
        }

        Collections.sort(restScores, Collections.reverseOrder());
        int maxScore = openSum;
        for (int i=0; i<M-K; i++){
            maxScore += restScores.get(i);
        }

        System.out.println(minScore+" "+maxScore);
    }
}

 

댓글