Minimum Time Required

  • + 1 comment
    def minTime(machines, goal):
        machines.sort()
        worst = machines[-1] * goal//len(machines)
        best = machines[0] * goal//len(machines)
        result = -1
        while worst>best+1:
            mid = best+(worst - best) // 2
            count = 0
            for machine in machines:
                count += mid//machine
            if count >=goal:
                worst = mid
                result = mid
            else:
                best = mid
        return result