Maximize sum of second minimums of each K length partitions of the array | Function to find the maximum sum of second smallest of each partition of size K ; Sort the array A in ascending order ; Store the maximum sum of second smallest of each partition of size K ; Select every ( K - 1 ) th element as second smallest element ; Update sum ; Print the maximum sum ; Driver Code ; Given size of partitions ; Given array A ; Size of the given array ; Function Call
def findSum ( A , N , K ) : NEW_LINE INDENT A . sort ( ) ; NEW_LINE sum = 0 ; NEW_LINE for i in range ( N // K , N , K - 1 ) : NEW_LINE INDENT sum += A [ i ] ; NEW_LINE DEDENT print ( sum ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT K = 4 ; NEW_LINE A = [ 2 , 3 , 1 , 4 , 7 , 5 , 6 , 1 ] ; NEW_LINE N = len ( A ) ; NEW_LINE findSum ( A , N , K ) ; NEW_LINE DEDENT