(C++) 1856. Maximum Subarray Min-Product
\n\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        vector<long> prefix = {0}; \n        for (auto x : nums) \n            pre
\n```\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        vector<long> prefix = {0}; \n        for (auto x : nums) \n            prefix.push_back(prefix.back() + x); \n        \n        long ans = 0; \n        stack<pair<int, int>> stk; \n        nums.push_back(0); \n        \n        for (int i = 0; i < nums.size(); ++i) {\n            int ii = i; \n            while (stk.size() && stk.top().second >= nums[i]) {\n                ii = stk.top().first; \n                int val = stk.top().second; \n                ans = max(ans, val * (prefix[i] - prefix[ii])); \n                stk.pop(); \n            }\n            stk.push(make_pair(ii, nums[i])); \n        }\n        return ans % 1\'000\'000\'007; \n    }\n};\n```
['C']