Easy to understand JavaScript solution (Monotonic Stack)
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nvar maxSumMinProduct = function(nums) {\n    const MODULO = BigInt(10 ** 9 + 7);\
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nvar maxSumMinProduct = function(nums) {\n    const MODULO = BigInt(10 ** 9 + 7);\n    const size = nums.length;\n    const prefixSum = Array(size + 1).fill(0);\n    const stack = [];\n    let result = BigInt(0);\n\n    nums.forEach((num, index) => prefixSum[index + 1] = prefixSum[index] + num);\n\n    for (let index = 0; index <= size; index++) {\n        const num = nums[index];\n\n        while (stack.length && (nums[stack.at(-1)] > num || index === size)) {\n            const minimum = BigInt(nums[stack.pop()]);\n            const last = stack.length ? stack.at(-1) + 1 : 0;\n            const sum = BigInt(prefixSum[index] - prefixSum[last]);\n            const product = minimum * sum;\n\n            if (result > product) continue;\n            result = product;\n        }\n        stack.push(index);\n    }\n    return result % MODULO;\n};\n```
['JavaScript']