simple cpp solution using stack
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    int maxSumMinProduct(vector<int>& nums) {\n        int n = nums.size();\n        vector<long long> sum(n);\n        sum[0] = nums[0];\n\n        // Calculate the prefix sum of the input array\n        for (int i = 1; i < n; i++) {\n            sum[i] = sum[i - 1] + nums[i];\n        }\n\n        vector<int> left(n);\n        vector<int> right(n);\n\n        stack<int> st;\n\n        // Calculate the left boundary for each element\n        for (int i = 0; i < n; i++) {\n            while (!st.empty() && nums[st.top()] >= nums[i]) {\n                st.pop();\n            }\n            left[i] = st.empty() ? 0 : st.top() + 1;\n            st.push(i);\n        }\n\n        // Clear the stack for reuse\n        while (!st.empty()) {\n            st.pop();\n        }\n\n        // Calculate the right boundary for each element\n        for (int i = n - 1; i >= 0; i--) {\n            while (!st.empty() && nums[st.top()] >= nums[i]) {\n                st.pop();\n            }\n            right[i] = st.empty() ? n - 1 : st.top() - 1;\n            st.push(i);\n        }\n\n        long long res = 0;\n        const int MOD = 1e9 + 7;\n\n        // Calculate the maximum min-product\n        for (int i = 0; i < n; i++) {\n            long long a = left[i];\n            long long b = right[i];\n            \n            // Calculate the sum of the subarray [left[i], right[i]]\n            long long subarray_sum = sum[b] - (a > 0 ? sum[a - 1] : 0);\n            \n            // Calculate the min-product for the current subarray\n            long long min_product = nums[i] * subarray_sum;\n            \n            // Update the result\n            res = max(res, min_product);\n        }\n\n        return res % MOD;\n    }\n};\n\n```
['C++']