human
Give me a code to maximum profit such that total stolen value is less than K to get bonus and the other steps required given the following:
Maximum profit such that total stolen value is less than K to get bonus | Function to find the maximum profit from the given values.
Iterating over every possible permutation.
Driver Code.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to maximum profit such that total stolen value is less than K to get bonus and the other steps required.
 def maxProfit ( value , N , K ) :
	value . sort ( )
	maxval = value [ N - 1 ]
	maxProfit = 0
	while True :
		curr_val = 0
		for i in range ( N ) :
			curr_val += value [ i ]
			if ( curr_val <= K ) :
				maxProfit = max ( curr_val + maxval * ( i + 1 ) , maxProfit )
		if not next_permutation ( value ) :
			break
	return maxProfit
def next_permutation ( p ) :
	for a in range ( len ( p ) - 2 , - 1 , - 1 ) :
		if p [ a ] < p [ a + 1 ] :
			b = len ( p ) - 1
			while True :
				if p [ b ] > p [ a ] :
					t = p [ a ]
					p [ a ] = p [ b ]
					p [ b ] = t
					a += 1
					b = len ( p ) - 1
					while a < b :
						t = p [ a ]
						p [ a ] = p [ b ]
						p [ b ] = t
						a += 1
						b -= 1
					return True
				b -= 1
	return False
N , K = 4 , 6
values = [ 5 , 2 , 7 , 3 ]
print ( maxProfit ( values , N , K ) )