Swift solution
Swift solution\nAt first, prepare three arrays:\n1. for i in 0..<c : leftBounds[i] = min index where nums[i] is min value in nums[left...i]\n2. for i in 0..<c :
Swift solution\nAt first, prepare three arrays:\n1. for i in 0..<c : leftBounds[i] = min index where nums[i] is min value in nums[left...i]\n2. for i in 0..<c : rightBounds[i] = max index where nums[i] is min value in nums[i...right]\n3. for i in 0...c : preSum[i] = sum of nums[0..<i]\n\nuse stacks of indexes to find left and right bounds.\nThen find result using these three arrays\n```\nclass Solution {\n    func maxSumMinProduct(_ nums: [Int]) -> Int {\n        let c = nums.count\n        var leftBounds = [Int](repeating: 0, count: c), rightBounds = leftBounds, preSum = [Int](repeating: 0, count: c + 1), leftStack = [Int](), rightStack = leftStack, result = 0\n        for i in 0..<c {\n            // leftBounds\n            while !leftStack.isEmpty && nums[leftStack.last!] >= nums[i] { leftStack.removeLast() }\n            leftBounds[i] = leftStack.isEmpty ? 0 : (leftStack.last! + 1)\n            leftStack.append(i)\n            // rightBounds\n            while !rightStack.isEmpty && nums[rightStack.last!] >= nums[c - 1 - i] { rightStack.removeLast() }\n            rightBounds[c - 1 - i] = rightStack.isEmpty ? (c - 1) : (rightStack.last! - 1)\n            rightStack.append(c - 1 - i)\n            // preSum\n            preSum[i + 1] = preSum[i] + nums[i]\n        }\n        for i in 0..<c {\n            result = max(result, (preSum[rightBounds[i] + 1] - preSum[leftBounds[i]]) * nums[i])\n        }\n        return result % 1_000_000_007\n    }\n}\n```
['Swift']