Monotonic Stack + Prefix Sum Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    void previousSmallerElement(vector<int> &nums, int &n, vector<int> &pse) {\n        stack<int> st;\n        for (int i = 0; i < n; i++) {\n            while (!st.empty() && nums[st.top()] >= nums[i])\n                st.pop();\n            if (!st.empty())\n                pse[i] = st.top();\n            st.push(i);\n        }\n    }\n    void nextSmallerElement(vector<int> &nums, int &n, vector<int> &nse) {\n        stack<int> st;\n        for (int i = n - 1; i >= 0; i--) {\n            while (!st.empty() && nums[st.top()] >= nums[i])\n                st.pop();\n            if (!st.empty())\n                nse[i] = st.top();\n            st.push(i);\n        }\n    }\n    int maxSumMinProduct(vector<int>& nums) {\n        int n = nums.size(), mod = 1e9 + 7;\n        vector<int> pse(n, -1), nse(n, n);\n        vector<long long> prefixSum(n + 1, 0);\n        long long int ans = 0, val;\n        previousSmallerElement(nums, n, pse);\n        nextSmallerElement(nums, n, nse);\n        for (int i = 0; i < n; i++) {\n            prefixSum[i + 1] = prefixSum[i] + nums[i];\n        }\n        for (int i = 0; i < n; i++) {\n            val = prefixSum[nse[i]] - prefixSum[pse[i] + 1];\n            ans = max(ans, val * nums[i]);\n        }\n        return ans % mod;\n    }\n};\n```
['C++']