human
Split array into equal length subsets with maximum sum of Kth largest element of each subset | Function to find the maximum sum of Kth largest element of M equal length partition.
Stores sum of K_th largest element of equal length partitions.
If N is not divisible by M.
Stores length of each partition.
If K is greater than length of partition.
Sort array in descending porder.
Traverse the array.
Update maxSum.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to split array into equal length subsets with maximum sum of Kth largest element of each subset and the other steps required.
 def maximumKthLargestsumPart ( arr , N , M , K ) :
	maxSum = 0
	if ( N % M != 0 ) :
		return - 1
	sz = ( N / M )
	if ( K > sz ) :
		return - 1
	arr = sorted ( arr )
	for i in range ( 0 , N // 2 ) :
		t = arr [ i ]
		arr [ i ] = arr [ N - i - 1 ]
		arr [ N - i - 1 ] = t
	for i in range ( 1 , M + 1 ) :
		maxSum += arr [ i * K - 1 ]
	return maxSum
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
	M = 2
	K = 1
	N = len ( arr )
	print ( maximumKthLargestsumPart ( arr , N , M , K ) )