C++ stack solution(o(N))
For each element nums[i] in array nums:\nWe treat nums[i] as minimum number in subarray which includes nums[i]\nLeft array storing the index of closest minimum 
For each element nums[i] in array nums:\nWe treat nums[i] as minimum number in subarray which includes nums[i]\nLeft array storing the index of closest minimum for nums[i] on the left side and right array on the right side.\nans = max(ans, nums[i] * getSum(left_bound_index, right_bound_index))\n```\nclass Solution {\npublic:\n    #define frr(i,j,k) for(int i=j;i<k;++i)\n    int maxSumMinProduct(vector<int>& nums) {\n        int n=nums.size();\n\t\t// prefix sum calculations\n        vector<long int>sum(n+1,0);\n        frr(i,0,n){\n            sum[i+1]=sum[i]+nums[i];\n        }\n\t\t// array for evaluation of left side\n        vector<int>v1=getstack(nums);\n        reverse(nums.begin(),nums.end());\n\t\t// array for evaluation of right side\n        vector<int>v2=getstack(nums);\n        reverse(v2.begin(),v2.end());\n        reverse(nums.begin(),nums.end());\n        long int ans=0;\n        frr(i,0,n){\n            v2[i]=n-1-v2[i];\n        }\n        for(int i=0;i<n;++i){\n            int left=v1[i];\n            int right=v2[i];\n            if(nums[i]>nums[left])left++;\n            if(nums[i]>nums[right])right--;\n            long int sum1=sum[right+1]-sum[left];\n            ans=max(ans,nums[i]*sum1);\n        }\n        int mod=1e9+7;\n        return ans%mod;\n    }\n    vector<int> getstack(vector<int>&nums){\n        stack<int>ss;\n        int n=nums.size();\n        vector<int>ans(n,0);\n        for(int i=0;i<n;++i){\n            if(ss.empty()){\n                ss.push(i);\n            }\n            else{\n                int fl=0;\n                while(!ss.empty()){\n                    int idx=ss.top();\n                    if(nums[idx]<nums[i]){\n                        ans[i]=idx;\n                        break;\n                    }\n                    ss.pop();\n                }\n                ss.push(i);\n            }\n        }\n        return ans;\n    }\n};\n```\n
[]