human
Find maximum subset | Function to calculate maximum sum possible by taking at most K elements that is divisibly by D.
Variable to store final answer.
Traverse all subsets.
Update ans if necessary conditions are satisfied.
Driver code.
Input.
Function call"
Solution in Python:
 ... Give me a code to find maximum subset and the other steps required?
assistant
#Here is code to find maximum subset and the other steps required.
 def maximumSum ( A , N , K , D ) :
	ans = 0
	for i in range ( ( 1 << N ) ) :
		sum = 0
		c = 0
		for j in range ( N ) :
			if ( i >> j & 1 ) :
				sum += A [ j ]
				c += 1
		if ( sum % D == 0 and c <= K ) :
			ans = max ( ans , sum )
	return ans
if __name__ == ' _ _ main _ _ ' :
	N = 5
	K = 3
	D = 7
	A = [ 1 , 11 , 5 , 5 , 18 ]
	print ( maximumSum ( A , N , K , D ) )