C++ solution using stack , prefix sum and suffix sum
for every number in nums just search for the smallest element in its left and  in right.\n#than just using prefix sum and suffix sum calculate your value for yo
**for every number in nums just search for the smallest element in its left and  in right.\n#than just using prefix sum and suffix sum calculate your value for your answer**\n\n\n```\nclass Solution {\npublic:\n    int mod = (int)1e9 + 7;\n    int maxSumMinProduct(vector<int>& nums) {\n        int n = nums.size();\n        \n        vector<int>left(n  , 0);\n        vector<int>right(n , 0);\n        \n        stack<int>st;\n        \n        for(int i=0 ; i < n ; i++){\n            int index = i;\n            while(!st.empty() and nums[st.top()] >= nums[i]){\n                index = left[st.top()];\n                st.pop();\n            }\n            \n            if(st.empty()){\n                left[i] = -1;\n            }else{\n                left[i] = index;\n            }\n            st.push(i);\n        }\n        \n        while(!st.empty())st.pop();        \n        \n        for(int i=n-1 ; i >= 0 ; i--){\n            int index = i;\n            while(!st.empty() and nums[st.top()] >= nums[i]){\n                index = right[st.top()];\n                st.pop();\n            }\n            \n            if(st.empty()){\n                right[i] = -1;\n            }else{\n                right[i] = index;\n            }\n            st.push(i);\n        }\n        \n        long long ans = INT_MIN;\n        \n        vector<long long>prefix(n);\n        \n        long long sum = 0;\n        \n        for(int i=0 ;  i < n ; i++){\n            sum = sum + nums[i];\n            prefix[i] = sum;\n        }\n        \n        for(int i=0 ; i < n ; i++){\n            long long sum = 0;\n            if(left[i] == -1 and right[i] == -1){\n                sum = prefix[n - 1] * nums[i]; \n            }else if(left[i] == -1){\n                sum = prefix[right[i]] * nums[i];\n            }else if(right[i] == -1){\n                sum = (prefix[n - 1] - prefix[left[i] - 1]) * nums[i];\n            }else{\n                sum = (prefix[right[i]] - prefix[left[i] - 1]) * nums[i];\n            }\n            \n            \n            ans = max(ans , sum);\n        }\n        \n        return ans % mod;\n        \n    }\n};\n```
['Stack', 'C', 'Monotonic Stack', 'Prefix Sum']