https://programmers.co.kr/learn/courses/30/lessons/43238
def solution(n, times):
answer = 0
left = 1
right = max(times) * n # κ°μ₯ λΉν¨μ¨μ μΈ μ¬μ¬ μκ°
while left <= right:
mid = (left+ right) // 2
count = 0
for i in times:
count += mid // i
# λͺ¨λ μ¬μ¬κ΄ μκ±°μΉκ³ midλΆ λμ nλͺ
μ΄μμ μ¬μ¬λ₯Ό ν μ μλ€λ©΄ break
if count >= n:
break
if count >= n:
right = mid - 1
elif count < n:
left = mid + 1
return left
print(solution(6, [7, 10]))
728x90
'Algorithms > Programmers' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
λ€νΈμν¬ DFS/BFS (0) | 2021.08.10 |
---|---|
νκ² λλ² (DFS/BFS lv2) (0) | 2021.08.06 |
μ€ν/ν lv2. κΈ°λ₯ κ°λ° (0) | 2021.07.25 |
μ€ν/ν 1λ² lv2 (0) | 2021.03.05 |
lv1. μ κ· μμ΄λ μΆμ² - μ κ·ννμ (0) | 2021.03.02 |