Minimize Cost with Replacement with other allowed | C ++ Program for the above approach ; this function returns the minimum cost of the array ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getMinCost ( int arr [ ] , int n ) { int min_ele = * min_element ( arr , arr + n ) ; return min_ele * ( n - 1 ) ; } int main ( ) { int arr [ ] = { 4 , 2 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << getMinCost ( arr , n ) << endl ; return 0 ; }