From 0db471098110ff206bccf43bfef93b6be6e03f22 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 1 Oct 2025 23:40:30 +0900 Subject: [PATCH] =?UTF-8?q?[20251001]=20PGM=20/=20LV2=20/=20=EA=B4=91?= =?UTF-8?q?=EB=AC=BC=20=EC=BA=90=EA=B8=B0=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\353\254\274 \354\272\220\352\270\260.md" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "suyeun84/202510/01 PGM LV2 \352\264\221\353\254\274 \354\272\220\352\270\260.md" diff --git "a/suyeun84/202510/01 PGM LV2 \352\264\221\353\254\274 \354\272\220\352\270\260.md" "b/suyeun84/202510/01 PGM LV2 \352\264\221\353\254\274 \354\272\220\352\270\260.md" new file mode 100644 index 00000000..124b224b --- /dev/null +++ "b/suyeun84/202510/01 PGM LV2 \352\264\221\353\254\274 \354\272\220\352\270\260.md" @@ -0,0 +1,57 @@ +```java +import java.util.*; + +class Solution { + public int solution(int[] picks, String[] minerals) { + int answer = 0; + + int totalPicks = picks[0] + picks[1] + picks[2]; + int limit = Math.min(minerals.length, totalPicks * 5); + + PriorityQueue pq = new PriorityQueue<>((a, b) -> { + if (b[0] != a[0]) return b[0] - a[0]; + if (b[1] != a[1]) return b[1] - a[1]; + return b[2] - a[2]; + }); + + int dia = 0, iron = 0, stone = 0, cnt = 0; + + for (int i = 0; i < limit; i++) { + String m = minerals[i]; + if (m.equals("diamond")) { + dia += 1; iron += 5; stone += 25; + } else if (m.equals("iron")) { + dia += 1; iron += 1; stone += 5; + } else { + dia += 1; iron += 1; stone += 1; + } + cnt++; + + if (cnt == 5) { + pq.offer(new int[]{stone, iron, dia}); + dia = iron = stone = 0; + cnt = 0; + } + } + if (cnt > 0) { + pq.offer(new int[]{stone, iron, dia}); + } + + while (!pq.isEmpty() && (picks[0] + picks[1] + picks[2] > 0)) { + int[] g = pq.poll(); + if (picks[0] > 0) { + answer += g[2]; + picks[0]--; + } else if (picks[1] > 0) { + answer += g[1]; + picks[1]--; + } else { answer += g[0]; + picks[2]--; + } + } + + return answer; + } +} + +```