입국심사

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

Explanation

Remember I said binary search is literally guessing the answer value and seeing if all of the logic and condition can be processed within that answer value.

Now we are guessing the time for all tasks to be completed and for a given guess of time, if more tasks than n are completed, we lower the upper boundary via end = mid -1. Otherwise, we move the lower boundary up via start = mid -1.

But be careful of the limits that the question gave. The waiting time is huuuge (Donald Trump’s yuuge). It can be 1,000,000,000 so set end to accomadate this. I did int(10e9) and I got some test cases wrong because my upper boundary is smaller than what the time can be.

My correct solution

def solution(n, times):
    start = 0
    end = int(10e18)

    while start<=end:
        mid = (end+start)//2
        count = sum(mid//time for time in times)
        if count>=n:
            end = mid-1
        else:
            start=mid+1
    return start

Notice here we are returning start instead of start-1 unlike our 징검다리. We return start because start represents the smallest possible time that allows processing n people, which is what we were searching for.