C++ solution || using stack and prefix sum
\n// consider each element as it is min value of subarray, then find such subarray and add those elements \nclass Solution {\npublic:\n    int maxSumMinProduct(
```\n// consider each element as it is min value of subarray, then find such subarray and add those elements \nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        int n = nums.size(); \n        vector<int> leftLimit(n), rightLimit(n);\n        vector<long long>prefixSum(n+1, 0);\n        \n        stack<int> stk;\n        \n        // store left index whose value is less than current element\n        for(int i=0; i<n; i++){\n            while(!stk.empty() && nums[stk.top()] >= nums[i]){\n                stk.pop();\n            }\n            leftLimit[i] = stk.empty() ? 0 : stk.top() + 1;\n            stk.push(i);\n            \n            prefixSum[i+1] = prefixSum[i] + (long long)nums[i];\n        }\n        \n        while(!stk.empty()) stk.pop();\n        // store right index whose value is less than current element\n        for(int i=n-1; i>=0; i--){\n            while(!stk.empty() && nums[stk.top()] >= nums[i]){\n                stk.pop();\n            }\n            rightLimit[i] = stk.empty() ? n-1 : stk.top() - 1;\n            stk.push(i);\n        }\n        \n        long long maxMinProduct = 0;\n        for(int i=0; i<n; i++){\n            long long rangeSum = prefixSum[rightLimit[i]+1] - prefixSum[leftLimit[i]];\n            long long curMinProduct = (long long)nums[i]*rangeSum;\n            maxMinProduct = max(maxMinProduct, curMinProduct);\n        }\n        return maxMinProduct % 1000000007;\n    }\n};\n```
['C', 'Monotonic Stack', 'Prefix Sum']