human
Split array into K non | Function find maximum sum of minimum and maximum of K subsets.
Stores the result.
Sort the array arr [ ] in decreasing order.
Traverse the range [ 0 , K ].
Sort the array S [ ] in ascending order.
Traverse the array S [ ].
If S { i ] is 1.
Stores the index of the minimum element of the i - th subset.
Traverse the array S [ ].
Update the counter.
Return the resultant sum.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to split array into K non and the other steps required.
 def maximumSum ( arr , S , N , K ) :
	ans = 0
	arr = sorted ( arr ) [ : : - 1 ]
	for i in range ( K ) :
		ans += arr [ i ]
	S = sorted ( S )
	for i in range ( K ) :
		if ( S [ i ] == 1 ) :
			ans += arr [ i ]
		S [ i ] -= 1
	counter = K - 1
	for i in range ( K ) :
		counter = counter + S [ i ]
		if ( S [ i ] != 0 ) :
			ans += arr [ counter ]
	return ans
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 13 , 7 , 17 ]
	S = [ 1 , 3 ]
	N = len ( arr )
	K = len ( S )
	print ( maximumSum ( arr , S , N , K ) )