Java solution:Similar to max rectangle in Histogram
\nclass Solution {\n    public int maxSumMinProduct(int[] nums) {\n        \n    ArrayDeque<Integer> dq = new ArrayDeque<Integer>();\n        long prefix[] = ne
```\nclass Solution {\n    public int maxSumMinProduct(int[] nums) {\n        \n    ArrayDeque<Integer> dq = new ArrayDeque<Integer>();\n        long prefix[] = new long[nums.length];\n        prefix[0] = nums[0];\n        for(int i=1;i<nums.length;i++)\n        {\n          prefix[i] = prefix[i-1] + nums[i];\n        }\n        \n        dq.push(-1);\n        long product = 0;\n        long mp = 0;\n        long M = (int)1e9 + 7;\n        \n        \n        \n        for(int i= 0; i<=nums.length;i++)\n        {\n           while((dq.peek()!=-1) && \n               nums[dq.peek()] > (i== nums.length? 0: nums[i]))\n           {\n               int pi = dq.pop();\n               long sum = 0;\n               if(dq.peek() == -1)\n               {\n                 sum = prefix[i-1];\n               }\n               else\n               {\n               sum = prefix[i-1]-prefix[dq.peek()];\n               }\n               \n               product = sum*nums[pi];\n              \n               \n               mp = Math.max(mp,product);\n           }\n           dq.push(i);\n        }\n        \n        mp = mp%M;\n        \n        return (int)mp;\n    }\n}\n```
[]