From a0c7b73625a3908b25fd005f44c1bec20894cdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A7=84?= Date: Thu, 13 Nov 2025 10:09:33 +0900 Subject: [PATCH] =?UTF-8?q?[20251113]=20PGM=20/=20LV2=20/=20=EB=B2=A0?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=97=98=EB=B2=94=20/=20=EA=B9=80=EB=AF=BC?= =?UTF-8?q?=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...44\355\212\270\354\227\230\353\262\224.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "zinnnn37/202511/13 PGM LV3 \353\262\240\354\212\244\355\212\270\354\227\230\353\262\224.md" diff --git "a/zinnnn37/202511/13 PGM LV3 \353\262\240\354\212\244\355\212\270\354\227\230\353\262\224.md" "b/zinnnn37/202511/13 PGM LV3 \353\262\240\354\212\244\355\212\270\354\227\230\353\262\224.md" new file mode 100644 index 00000000..d17e3992 --- /dev/null +++ "b/zinnnn37/202511/13 PGM LV3 \353\262\240\354\212\244\355\212\270\354\227\230\353\262\224.md" @@ -0,0 +1,55 @@ +```java +import java.util.*; + +public class PGM_LV2_베스트엘범 { + + private static int len; + + private static Map> order; + private static Map cnt; + + private static class Node implements Comparable { + int id; + int cnt; + + Node(int id, int cnt) { + this.id = id; + this.cnt = cnt; + } + + @Override + public int compareTo(Node o) { + return Integer.compare(o.cnt, this.cnt); + } + } + + public int[] solution(String[] genres, int[] plays) { + len = genres.length; + + order = new HashMap<>(); + cnt = new TreeMap<>(Collections.reverseOrder()); + + for (int i = 0; i < genres.length; i++) { + cnt.put(genres[i], cnt.getOrDefault(genres[i], 0) + plays[i]); + + order.putIfAbsent(genres[i], new PriorityQueue<>()); + order.get(genres[i]).offer(new Node(i, plays[i])); + } + + List sortedGenres = new ArrayList<>(order.keySet()); + sortedGenres.sort((a, b) -> Integer.compare(cnt.get(b), cnt.get(a))); + + List res = new ArrayList<>(); + + for (String genre : sortedGenres) { + Queue pq = order.get(genre); + + for (int i = 0; i < 2 && !pq.isEmpty(); i++) { + res.add(pq.poll().id); + } + } + + return res.stream().mapToInt(i -> i).toArray(); + } +} +``` \ No newline at end of file