From 7c15455feb46cd6c73a746c81cc174eeb55c2350 Mon Sep 17 00:00:00 2001 From: yongjun-0903 <472dyd@gmail.com> Date: Mon, 12 May 2025 22:53:38 +0900 Subject: [PATCH] =?UTF-8?q?kyj=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A4=20=EB=94=94=ED=8E=9C=EC=8A=A4=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\212\244 \352\262\214\354\236\204.py" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "\352\271\200\354\232\251\354\244\200/\353\224\224\355\216\234\354\212\244 \352\262\214\354\236\204.py" diff --git "a/\352\271\200\354\232\251\354\244\200/\353\224\224\355\216\234\354\212\244 \352\262\214\354\236\204.py" "b/\352\271\200\354\232\251\354\244\200/\353\224\224\355\216\234\354\212\244 \352\262\214\354\236\204.py" new file mode 100644 index 0000000..a2d1bd8 --- /dev/null +++ "b/\352\271\200\354\232\251\354\244\200/\353\224\224\355\216\234\354\212\244 \352\262\214\354\236\204.py" @@ -0,0 +1,21 @@ +import heapq + +def solution(n, k, enemy): + ks = [] + rounds = len(enemy) + + for i in range(rounds): + current = enemy[i] + + if len(ks) < k: + heapq.heappush(ks, current) + elif k > 0 and ks and current > ks[0]: + n -= heapq.heappop(ks) + heapq.heappush(ks, current) + else: + n -= current + + if n < 0: + return i + + return rounds