Skip to content

Commit 02b8deb

Browse files
authored
[BOJ] 2865 나는 위대한 슈퍼스타 K (S4)
1 parent 05a4192 commit 02b8deb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

정건우/2주차/260108.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//https://www.acmicpc.net/problem/2865
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.*;
6+
7+
public class BOJ_S4_2865_나는위대한슈퍼스타K {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
StringTokenizer st = new StringTokenizer(br.readLine());
11+
12+
int N = Integer.parseInt(st.nextToken());
13+
int M = Integer.parseInt(st.nextToken());
14+
int K = Integer.parseInt(st.nextToken());
15+
16+
Map<Integer, Double> map = new HashMap<>();
17+
18+
for (int i = 0; i < M; i++) {
19+
st = new StringTokenizer(br.readLine());
20+
21+
for (int j = 0; j < N; j++) {
22+
int idx = Integer.parseInt(st.nextToken());
23+
double score = Double.parseDouble(st.nextToken());
24+
25+
if (map.getOrDefault(idx, 0.0) < score) {
26+
map.put(idx, score);
27+
}
28+
}
29+
}
30+
31+
PriorityQueue<Double> pq = new PriorityQueue<>(map.size(), Collections.reverseOrder());
32+
pq.addAll(map.values());
33+
map.clear();
34+
35+
double ans = 0.0;
36+
37+
for (int i = 0; i < K && !pq.isEmpty(); i++) {
38+
ans += pq.poll();
39+
}
40+
41+
System.out.printf("%.1f", ans);
42+
43+
}
44+
}

0 commit comments

Comments
 (0)