c++ | easy to understand | short
\n# Code\n\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        int n = nums.size();\n        int left[n], right[n];\n        long
\n# Code\n```\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        int n = nums.size();\n        int left[n], right[n];\n        long long int sum[n];\n        sum[0] = nums[0];\n        for(int i=1;i<n;i++){\n            sum[i] = sum[i-1]+nums[i];\n        }\n        stack<pair<int, int> > s1, s2;\n        for (int i = 0; i < n; ++i) {\n            int cnt = 1;\n            while (!s1.empty() && (s1.top().first) > nums[i]) {\n                cnt += s1.top().second;\n                s1.pop();\n            }\n            s1.push({ nums[i], cnt });\n            left[i] = cnt;\n        }\n        for (int i = n - 1; i >= 0; --i) {\n            int cnt = 1;\n            while (!s2.empty() && (s2.top().first) >= nums[i]) {\n                cnt += s2.top().second;\n                s2.pop();\n            }\n\n            s2.push({ nums[i], cnt });\n            right[i] = cnt;\n        }\n        long long int res =0;\n        for(int i=0;i<n;i++){\n            int a = i-left[i]+1;\n            int b = i+right[i]-1;\n            long long int subArraySum;\n            if(a>0)\n                subArraySum = sum[b]-sum[a-1];\n            else\n                subArraySum = sum[b];\n            res = max(res, subArraySum*nums[i]);\n        }\n        return res%1000000007;\n    }\n};\n```
['C++']