컴공생의 다이어리

[프로그래머스] 선입 선출 스케줄링 - 파이썬(Python) 본문

Development/Algorithm & Coding Test

[프로그래머스] 선입 선출 스케줄링 - 파이썬(Python)

컴공 K 2022. 8. 3. 00:01

[프로그래머스] 선입 선출 스케줄링 - 파이썬(Python)

 

 

 

def solution(n, cores):
    len_cores = len(cores)

    if n < len_cores:
        return n

    n -= len_cores
    left, right = 1, max(cores) * n

    while left < right:  # 이분 탐색
        mid = (left + right) // 2
        temp = 0
        for c in cores:
            temp += mid // c

        if temp >= n:
            right = mid
        else:
            left = mid + 1

    n -= sum(map(lambda x: (right - 1) // x, cores))

    for i in range(len_cores):
        if right % cores[i] == 0:
            n -= 1
            if n == 0:
                return i + 1

 

 

 

https://school.programmers.co.kr/learn/courses/30/lessons/12920

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

728x90
Comments