Minimum cost to make array size 1 by removing larger of pairs | CPP program to find minimum cost to reduce array size to 1 , ; function to calculate the minimum cost ; Minimum cost is n - 1 multiplied with minimum element . ; driver code .
#include <bits/stdc++.h> NEW_LINE using namespace std ; int cost ( int a [ ] , int n ) { return ( n - 1 ) * ( * min_element ( a , a + n ) ) ; } int main ( ) { int a [ ] = { 4 , 3 , 2 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << cost ( a , n ) << endl ; return 0 ; }