[DAY24]Minimum Time Required

Sherlock Chiou
1 min readNov 1, 2019

--

Solution 1: Traverse through day and check if the number of product meet the the goal.

Solution 2: Binary Search Algorithm. The upper bound would be all of the machines produce an item in the lowest speed(The machine that needs longest days to produce an item). The lower bound would be all of the machines produce an item in the fastest speed(The machine that needs shortest days to produce an item). And during the search, unlike ordinary binary search, what we need to find here is the minimum days to produce the goal. So when the production is greater than the goal, what we need to do here is to set the upper bound to mid rather than mid+1. Because there might be severals days produce the amount equivalent to the goal. And when the production is smaller than the goal, like ordinary binary search, we set the lower bound to mid-1 to make sure the while to be terminated.

--

--

Sherlock Chiou
Sherlock Chiou

Written by Sherlock Chiou

Be Effective and Optimize for Learning

No responses yet