class Solution:
    def minEatingSpeed(self, A: List[int], h: int) -> int:
        """tc O(Nlg(max(A))  sc O(1)
        main idea: goal is to minimize k s.t. at speed of k/ hour can finish sum(A); 
                    condition: (1)time cost at pile i--->  ceil(A[i]/k)
                               (2) k <= A[i] and len(A) <= h
                    ==>  l,r = 1, (max val in A)+1
        """
        l,r = 1,max(A)+1 # or max(A)
        while l < r :
            k = l + (r-l)//2
            cost = 0
            for a in A:
                cost +=(p+m-1) /m  # equal to  math.ceil(a/k) 
            if cost > h: # k is too small 
                l = k + 1
            else:
                r = k # keep closer 
        return l # or  r