ν°μ€ν 리 λ·°
π¨π» μ½λ©ν
μ€νΈ/νλ‘κ·Έλλ¨Έμ€
νλ‘κ·Έλλ¨Έμ€: λμ€ν¬ 컨νΈλ‘€λ¬
dirmathfl 2020. 10. 11. 23:15728x90
λ°μν
λ¬Έμ
λ¬Έμ νμ΄
νλ λμ€ν¬μ μμ²λ μμ μ μμ μ΄ μ’ λ£λλ μκ°μ΄ λΉ λ₯Έ μμΌλ‘ μ²λ¦¬νλλ‘ νμ¬ νκ· μ²λ¦¬ μκ°μ λ°ννλ λ¬Έμ μ΄λ€. μμ²λ μμ μμΌλ‘ μ λ ¬ νμ μ²λ¦¬ν μμ μ νλμ© `pop`νμ¬ `heap`μ ν΅ν΄ μ²λ¦¬ μκ°μ΄ κ°μ₯ ν° μμ λΆν° 루νΈκ° λλλ‘ μ μ§νλ€. μ΄μ κ°μ κ³Όμ μ ν΅ν΄, λ¬Έμ μ μꡬνλ κ²κ³Ό κ°μ΄ μμ μ μ²λ¦¬ν μ μλ€.
μ½λ
import heapq
from collections import deque
RQEUST = 0
def solution(jobs):
answer = 0
jobs.sort()
q = deque(jobs)
current_time = q[0][RQEUST]
num_jobs = len(q)
heap = []
while q:
start, process = q.popleft()
current_time += process
answer += current_time - start
while q and q[0][RQEUST] < current_time:
start, process = q.popleft()
heapq.heappush(heap, [-process, start])
while heap:
process, start = heapq.heappop(heap)
q.appendleft([start, -process])
return answer // num_jobs
728x90
λ°μν
'π¨βπ» μ½λ©ν μ€νΈ > νλ‘κ·Έλλ¨Έμ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
νλ‘κ·Έλλ¨Έμ€: SQL - SELECT (0) | 2020.10.21 |
---|---|
νλ‘κ·Έλλ¨Έμ€: λ¨μμΉ΄λ©λΌ (0) | 2020.10.11 |
νλ‘κ·Έλλ¨Έμ€: λ±κ΅£κΈΈ (0) | 2020.10.05 |
νλ‘κ·Έλλ¨Έμ€: λ λ§΅κ² (0) | 2020.09.04 |
νλ‘κ·Έλλ¨Έμ€: νλ¦°ν° (0) | 2020.09.04 |
λκΈ
κΈ λ³΄κ΄ν¨
μ΅κ·Όμ μ¬λΌμ¨ κΈ
μ΅κ·Όμ λ¬λ¦° λκΈ