-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
65-9kyo-hwang #224
base: main
Are you sure you want to change the base?
65-9kyo-hwang #224
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ¬Έμ λ€ νκ³ , κ΅ν©λ μ½λ 보λ round λ³μλͺ μ΄ λ λͺ νν΄μ λ°λ‘ λ λ€ μμ νμ΅λλ€ γ γ γ γ
import heapq
def solution(n, k, enemy):
answer = len(enemy)
pq = []
my = n
card = k
for round in range(len(enemy)):
my -= enemy[round]
heapq.heappush(pq, -enemy[round])
if my < 0:
if card > 0:
my += heapq.heappop(pq) * -1
card -= 1
else :
return round
return answer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ€λλ§μ 보λ μ΅λν μ₯μ~
from heapq import *
def solution(n, k, enemy):
round = 0
fight = []
for e in enemy:
round += 1
n -= e
heappush(fight, -e)
while n < 0 and k > 0:
k -= 1
n -= heappop(fight)
if n < 0 :
round -= 1
break
return round
π λ¬Έμ λ§ν¬
λνμ€ κ²μ
βοΈ μμλ μκ°
1μκ°
β¨ μλ μ½λ
μ΅λ$1,000,000$ λΌμ΄λμ κ±Έμ³ μ λ€μ΄ λ€μ΄μ¨λ€. κ·Έλ¦¬κ³ μ΅λ $500,000$ λΌμ΄λλ₯Ό
무μ κΆ
μ μ¬μ©ν΄ λ³μ¬ μλͺ¨λ₯Ό 0μΌλ‘ λ§λ€ μ μλ€.λ°±νΈλνΉ λ±μ μ΄μ©ν΄ λͺ¨λ κ²½μ°μ μλ₯Ό ꡬνκΈ°μλ μ«μκ° λ무 ν¬λ€. λΌμ΄λκ° μ΅λ$1,000,000$ μ΄κΈ° λλ¬Έμ $O(N^2)$ νμ΄λ²λ λΆκ°λ₯νλ€. μ¦ $O(N logN)$ νμ΄λ²μ μ¬μ©ν΄μΌ νλ€.
μ§κ΄μ μΌλ‘ μκ°νμ λλ, 무μ κΆμ κ°λ₯ν "μ μ μκ° λ§μ λΌμ΄λ"μ μ¬μ©νλ κ²μ΄ μ’λ€. κ·Έλ¬λ μ΄λ¬ν λ°©λ²μ "μ ννμ"μΌλ‘ λΆκ°λ₯νκ³ , κ·Έλ λ€κ³ μμμ μΈκΈν κ²μ²λΌ λͺ¨λ κ²½μ°μ μλ₯Ό λ€ νμΈν μλ μλ€.
λ°λΌμ μ¬κΈ°μλ μ°μ μμ νλ₯Ό μ¬μ©νλ€. μ리λ κ°λ¨νλ€.
i. λ§μ½ λ μ΄μ 무μ κΆμ μ¬μ©ν μ μλ€λ©΄ λΌμ΄λλ₯Ό μ€λ¨νλ€.
ii. μλλΌλ©΄ MaxHeapμμ μ§λ λΌμ΄λ μ€ κ°μ₯ μ μ΄ λ§μλ λΌμ΄λμ μ μλ₯Ό popν΄ κ·Έ μ λ§νΌ λ³μ¬ μλ₯Ό 볡μμν€κ³ λ¨μ 무μ κΆ νμλ₯Ό 1 μ°¨κ°μν¨λ€.
μ΄λ° μμΌλ‘ MaxHeapμ μ¬μ©νλ©΄$O(logN)$ μκ°λ³΅μ‘λλ‘ μ§λ λΌμ΄λ μ€ κ°μ₯ μ μ΄ λ§μ λΌμ΄λ μ 보λ₯Ό μ»μ΄μ¬ μ μκ² λλ€.
π μλ‘κ² μκ²λ λ΄μ©
μ€μΌ 그리λ μ νμ μν리λμ§ λͺ¨λ₯΄κ² λ€.
μμ μλ μ½ν λ³Ό λ 그리λ/μ°μ μμν μ°λ λ¬Έμ λͺ» νμμλλ°, μ΄κ²λ νμ°Έ μ½μ§νλ€κ° κ²¨μ° ν΄κ²°νλ€ ν ...