human
Find maximum height to cut all chocolates horizontally such that at least K amount remains | Function to find the sum of remaining chocolate after making the horizontal cut at height mid.
Stores the sum of chocolates.
Traverse the array arr [ ].
If the height is at least mid.
Return the possible sum.
Function to find the maximum horizontal cut made to all the chocolates such that the sum of the remaining element is at least K.
Ranges of Binary Search.
Perform the Binary Search.
Find the sum of removed after making cut at height mid.
If the chocolate removed is same as the chocolate needed then return the height.
If the chocolate removed is less than chocolate needed then shift to the left range.
Otherwise , shift to the right range.
Return the possible cut.
Driver Code"
How can the above be solved in Python?

What is a code to find maximum height to cut all chocolates horizontally such that at least K amount remains and the other steps required?
assistant
#Here is code to find maximum height to cut all chocolates horizontally such that at least K amount remains and the other steps required.
 def cal ( arr , mid ) :
	chocolate = 0
	for i in arr :
		if i >= mid :
			chocolate += i - mid
	return chocolate
def maximumCut ( arr , K ) :
	low = 0
	high = max ( arr )
	while low <= high :
		mid = ( low + high ) // 2
		chocolate = cal ( arr , mid )
		if chocolate == K :
			return mid
		elif chocolate < K :
			high = mid - 1
		else :
			low = mid + 1
			if mid > high :
				high = mid
	return high
N , K = 4 , 7
arr = [ 15 , 20 , 8 , 17 ]
print ( maximumCut ( arr , K ) )