[cpp]100%(faster)||stack||O(n)
\n#define mod 1000000007\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        int n=nums.size();long rt[n+2],lf[n+2];\n        lon
```\n#define mod 1000000007\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        int n=nums.size();long rt[n+2],lf[n+2];\n        long preSum[n+2];preSum[0]=0;\n        // preSum \n        for(int i=1;i<=n;i++)\n            preSum[i]=preSum[i-1]+nums[i-1];\n        stack<int>st;\n        // first leftmost index where element are less than current\n        for(int i=1;i<=n;i++)\n        {\n            while(st.size()&&nums[st.top()-1]>=nums[i-1])\n                st.pop();\n            if(st.size()==0)lf[i]=0;\n            else lf[i]=st.top();\n            st.push(i);\n        }\n        while(st.size())\n            st.pop();\n        //rightMost index where element are not less than current\n        for(int i=n;i>=1;i--)\n        {\n            while(st.size()&&nums[st.top()-1]>=nums[i-1])\n                st.pop();\n            if(st.size()==0)rt[i]=n;\n            else rt[i]=st.top()-1;\n            st.push(i);\n        }\n        long ans=0;\n        for(int i=1;i<=n;i++)\n            {\n          long tmp=(nums[i-1]*(preSum[rt[i]]-preSum[lf[i]]));\n           ans=max(ans,tmp);\n        }\n        int z=ans%mod;\n        return z;\n            \n    }\n};\n```
['Stack', 'C', 'C++']