[Python3] mono-stack
\n\nclass Solution:\n    def maxSumMinProduct(self, nums: List[int]) -> int:\n        prefix = [0]\n        for x in nums: prefix.append(prefix[-1] + x)\n      
\n```\nclass Solution:\n    def maxSumMinProduct(self, nums: List[int]) -> int:\n        prefix = [0]\n        for x in nums: prefix.append(prefix[-1] + x)\n        \n        ans = 0 \n        stack = []\n        for i, x in enumerate(nums + [-inf]): # append "-inf" to force flush all elements\n            while stack and stack[-1][1] >= x: \n                _, xx = stack.pop()\n                ii = stack[-1][0] if stack else -1 \n                ans = max(ans, xx*(prefix[i] - prefix[ii+1]))\n            stack.append((i, x))\n        return ans % 1_000_000_007\n```
['Python3']