1
# Runtime: 5298 ms (Top 60.74%) | Memory: 27.4 MB (Top 98.14%)5
def minSpeedOnTime(self, dist: List[int], hour: float) -> int:6
# the speed upper is either the longest train ride: max(dist),7
# or the last train ride divide by 0.01: ceil(dist[-1] / 0.01).8
# notice: "hour will have at most two digits after the decimal point"9
upper = max(max(dist), ceil(dist[-1] / 0.01))11
# the function to calcute total time consumed12
total = lambda speed: sum(map(lambda x: ceil(x / speed), dist[:-1])) + (15
# the case of impossible to arrive office on time16
if total(upper) > hour:19
# binary search: find the mimimal among "all" feasible answers20
left, right = 1, upper22
mid = left + (right - left) // 224
left = mid + 1 # should be larger26
right = mid # should explore a smaller one