오늘의 문제 >> 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);
}
}
'TIL🔥 > 코딩테스트' 카테고리의 다른 글
[항해99클럽] Java 비기너_Day 15 학생 인기도 측정 (1) | 2025.04.18 |
---|---|
[항해99클럽] Java 비기너_Day 13 단어 정렬 (0) | 2025.04.16 |
[항해99클럽] Java 비기너_Day 12 임스와 함께하는 미니게임 (0) | 2025.04.15 |
[항해99클럽] Java 비기너_Day 11 Repeated DNA Sequences (0) | 2025.04.14 |
[항해99클럽] Java 비기너_Day 10 평행선 (1) | 2025.04.13 |
댓글