human
Minimum time required to schedule K processes | Function to find minimum required time to schedule all process.
Stores max element from A [ ].
Find the maximum element.
Stores frequency of each element.
Stores minimum time required to schedule all process.
Count frequencies of elements.
Find the minimum time.
Decrease the value of K.
Increment tmp [ i / 2 ].
Increment the count.
Return count , if all process are scheduled.
Increment count.
Return the count.
If it is not possible to schedule all process.
Driver code"
How can the above be solved in Python?
 Give me a code to minimum time required to schedule K processes and the other steps required?
assistant
#Here is code to minimum time required to schedule K processes and the other steps required.
 def minTime ( A , n , K ) :
	max_ability = A [ 0 ]
	for i in range ( 1 , n ) :
		max_ability = max ( max_ability , A [ i ] )
	tmp = [ 0 for i in range ( max_ability + 1 ) ]
	count = 0
	for i in range ( n ) :
		tmp [ A [ i ] ] += 1
	i = max_ability
	while ( i >= 0 ) :
		if ( tmp [ i ] != 0 ) :
			if ( tmp [ i ] * i < K ) :
				K -= ( i * tmp [ i ] )
				tmp [ i // 2 ] += tmp [ i ]
				count += tmp [ i ]
				if ( K <= 0 ) :
					return count
			else :
				if ( K % i != 0 ) :
					count += ( K // i ) + 1
				else :
					count += ( K // i )
				return count
		i -= 1
	return - 1
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 1 , 7 , 2 , 4 ]
	N = 5
	K = 15
	print ( minTime ( arr , N , K ) )