Sum of minimum element of all subarrays of a sorted array | C ++ implementation of the above approach ; Function to find the sum of minimum of all subarrays ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMinSum ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] * ( n - i ) ; return sum ; } int main ( ) { int arr [ ] = { 3 , 5 , 7 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMinSum ( arr , n ) ; return 0 ; }