human
Find minimum value of the expression by choosing K elements from given array | Function to find the minimum possible of the expression by choosing exactly K ( ? N ) integers form given array arr.
Sorting the array for least k element selection.
Select first k elements from sorted array.
Return value of solved expression.
Driver code.
Function call"
Solution in Python:
assistant
#Here is code to find minimum value of the expression by choosing K elements from given array and the other steps required.
 def minimumValue ( arr , n , k ) :
	arr . sort ( ) ;
	answer = 0 ;
	for i in range ( k ) :
		answer += arr [ i ] * arr [ i ] ;
	return answer * ( 2 * k - 2 ) ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 4 , 21 , 5 , 3 , 8 ] ;
	k = 3 ;
	n = len ( arr ) ;
	print ( minimumValue ( arr , n , k ) ) ;