human
Write me a code to maximum possible sum of non and the other steps required given the following:
Maximum possible sum of non | Function to find the maximum sum not exceeding K possible by selecting a subset of non - adjacent elements.
Base Case.
Not selecting current element.
If selecting current element is possible.
Return answer.
Driver Code.
Given array arr [ ].
Given K.
Function Call"
Solution in Python:
assistant
#Here is code to maximum possible sum of non and the other steps required.
 def maxSum ( a , n , k ) :
	if ( n <= 0 ) :
		return 0
	option = maxSum ( a , n - 1 , k )
	if ( k >= a [ n - 1 ] ) :
		option = max ( option , a [ n - 1 ] + maxSum ( a , n - 2 , k - a [ n - 1 ] ) )
	return option
if __name__ == ' _ _ main _ _ ' :
	arr = [ 50 , 10 , 20 , 30 , 40 ]
	N = len ( arr )
	K = 100
	print ( maxSum ( arr , N , K ) )