human
Minimum count of elements to be inserted in Array to form all values in [ 1 , K ] using subset sum | Function to find the count of minimum elements to be inserted to form every number in a range.
Stores the count of numbers needed.
Stores the numbers upto which every numbers can be formed.
Stores the index of the array arr [ ].
Iterate until requiredSum is less than or equal to K.
If i is less than N and requiredSum is greater than or equal to arr [ i ].
Increment requiredSum by arr [ i ].
Increment i by 1.
Otherwise.
Increment count by 1.
Increment requiredSum by requiredSum.
Return result.
Driver Code.
Input.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to minimum count of elements to be inserted in Array to form all values in [ 1 , K ] using subset sum and the other steps required.
 def minElements ( arr , N , K ) :
	count = 0
	requiredNum = 1
	i = 0
	while ( requiredNum <= K ) :
		if ( i < N and requiredNum >= arr [ i ] ) :
			requiredNum += arr [ i ]
			i += 1
		else :
			count += 1
			requiredNum += requiredNum
	return count
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 3 ]
	K = 6
	N = len ( arr )
	print ( minElements ( arr , N , K ) )