From 7f719e7175d2a47f9d9ab7e2ef6088209543ae68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Thu, 16 Oct 2025 19:12:37 +0900 Subject: [PATCH] =?UTF-8?q?[20251016]=20PGM=20/=20LV2=20/=20=EB=8D=94=20?= =?UTF-8?q?=EB=A7=B5=EA=B2=8C=20/=20=EA=B0=95=EC=8B=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \353\215\224 \353\247\265\352\262\214.md" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "ksinji/202510/16 PGM \353\215\224 \353\247\265\352\262\214.md" diff --git "a/ksinji/202510/16 PGM \353\215\224 \353\247\265\352\262\214.md" "b/ksinji/202510/16 PGM \353\215\224 \353\247\265\352\262\214.md" new file mode 100644 index 00000000..9b3d79a1 --- /dev/null +++ "b/ksinji/202510/16 PGM \353\215\224 \353\247\265\352\262\214.md" @@ -0,0 +1,32 @@ +```java +import java.util.*; + +class Solution { + public int solution(int[] scoville, int K) { + PriorityQueue pq = new PriorityQueue<>(); + + for (int i: scoville){ + pq.add(i); + } + + int answer = 0; + + while (!pq.isEmpty() && pq.peek() < K) { + // pq의 크기가 2 미만이면 음식 섞기 불가 + // 근데 모든 음식의 스코빌 지수가 아직 K 이상이 아니므로 -1 리턴 + if (pq.size() < 2){ + return -1; + } + + int first = pq.poll(); + int second = pq.poll(); + int newS = first + (second*2); + + pq.add(newS); + answer++; + } + + return answer; + } +} +``` \ No newline at end of file