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