Split array into K | Function to find the minimum sum of 2 nd smallest elements of each subset ; Sort the array ; Stores minimum sum of second elements of each subset ; Traverse first K 2 nd smallest elements ; Update their sum ; Prthe sum ; Driver Code ; Given Array ; Given size of the array ; Given subset lengths
def findMinimum ( arr , N , K ) : NEW_LINE INDENT arr = sorted ( arr ) NEW_LINE ans = 0 NEW_LINE for i in range ( 1 , 2 * ( N // K ) , 2 ) : NEW_LINE INDENT ans += arr [ i ] NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 11 , 20 , 5 , 7 , 8 , 14 , 2 , 17 , 16 , 10 ] NEW_LINE N = len ( arr ) NEW_LINE K = 5 NEW_LINE findMinimum ( arr , N , K ) NEW_LINE DEDENT