Smallest possible integer K such that ceil of each Array element when divided by K is at most M | ''python program for the above approach ; ''Function to check if the sum of ceil values of the arr[] for the K value is at most M or not ; '' Stores the sum of ceil values ; '' Update the sum ; '' Return true if sum is less than  or equal to M, false otherwise ; ''Function to find the smallest possible integer K such that ceil(arr[0]/K) + ceil(arr[1]/K) +....+ ceil(arr[N-1]/K) is less than or equal to M ; '' Stores the low value ; '' Stores the high value ; '' Stores the middle value ; '' Update the mid value ; '' Check if the mid value is K ; '' Update the low value ; '' Update the high value ; '' Check if low is K or high is K  and return it ; ''Driver Code
import math NEW_LINE def isvalid ( arr , K , N , M ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT sum += math . ceil ( arr [ i ] * 1.0 / K ) NEW_LINE DEDENT return sum <= M NEW_LINE DEDENT def smallestValueForK ( arr , N , M ) : NEW_LINE INDENT low = 1 NEW_LINE high = arr [ 0 ] NEW_LINE for i in range ( 1 , len ( arr ) ) : NEW_LINE INDENT high = max ( high , arr [ i ] ) NEW_LINE DEDENT mid = 0 NEW_LINE while ( high - low > 1 ) : NEW_LINE INDENT mid = ( high + low ) // 2 NEW_LINE if ( not isvalid ( arr , mid , N , M ) ) : NEW_LINE INDENT low = mid + 1 NEW_LINE DEDENT else : NEW_LINE INDENT high = mid NEW_LINE DEDENT DEDENT if ( isvalid ( arr , low , N , M ) ) : NEW_LINE INDENT return low NEW_LINE DEDENT else : NEW_LINE INDENT return high NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 4 , 3 , 2 , 7 ] NEW_LINE N = len ( arr ) NEW_LINE M = 5 NEW_LINE print ( smallestValueForK ( arr , N , M ) ) NEW_LINE DEDENT