From f296c36925065bee2c05b9de24a8d3a209ee632e Mon Sep 17 00:00:00 2001 From: MinwooJe Date: Wed, 18 Jun 2025 14:20:58 +0900 Subject: [PATCH] =?UTF-8?q?lv2=5F=EB=8D=94=EB=A7=B5=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2_\353\215\224\353\247\265\352\262\214.py" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "MinwooJe/6\354\243\274\354\260\250_\354\232\260\354\204\240\354\210\234\354\234\204_\355\201\220/lv2_\353\215\224\353\247\265\352\262\214.py" diff --git "a/MinwooJe/6\354\243\274\354\260\250_\354\232\260\354\204\240\354\210\234\354\234\204_\355\201\220/lv2_\353\215\224\353\247\265\352\262\214.py" "b/MinwooJe/6\354\243\274\354\260\250_\354\232\260\354\204\240\354\210\234\354\234\204_\355\201\220/lv2_\353\215\224\353\247\265\352\262\214.py" new file mode 100644 index 0000000..464427b --- /dev/null +++ "b/MinwooJe/6\354\243\274\354\260\250_\354\232\260\354\204\240\354\210\234\354\234\204_\355\201\220/lv2_\353\215\224\353\247\265\352\262\214.py" @@ -0,0 +1,21 @@ +import heapq as hq + +def solution(scoville, K): + hq.heapify(scoville) + result = 0 + + while len(scoville) >= 2: + min1 = hq.heappop(scoville) + min2 = hq.heappop(scoville) + + if min1 >= K: return result + + mixed = min1 + min2 * 2 + hq.heappush(scoville, mixed) + result += 1 + + if hq.heappop(scoville) >= K: + return result + else: + return -1 +