C++(finally got it..)
\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        long mod = 1e9 + 7;\n\t\tlong res = 0;\n\t\tnums.push_back(-1);\n\t\tint len
```\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        long mod = 1e9 + 7;\n\t\tlong res = 0;\n\t\tnums.push_back(-1);\n\t\tint length = nums.size();\n\t\t//Monotone Stack\n\t\tstack<int> st;\n\t\tvector<long> dp(length);\n\t\tdp[0] = nums[0];\n\t\tfor (int i = 1; i < length-1; i++) { \n\t\t\tdp[i] = dp[i - 1] + nums[i]; \n\t\t}\n\t\tfor (int i = 0; i < length; i++) {\n\t\t\twhile (!st.empty() && nums[i] < nums[st.top()]) {\n\t\t\t\tint top = st.top();\n\t\t\t\tst.pop();\n\n\t\t\t\tif (!st.empty()) {\n\t\t\t\t\tlong x = dp[i - 1] - dp[st.top()];\n\t\t\t\t\t//cout << x<<endl;\n\t\t\t\t\tres = (x * nums[top]) > res ? (x * nums[top]) : res;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t//cout << "enter?"<< top<<endl;\n\t\t\t\t\tlong x = dp[i-1];\n\t\t\t\t\tres = (x * nums[top]) > res ? (x * nums[top]) : res;\n\t\t\t\t}\n\t\t\t}\n\t\t\tst.push(i);\n\t\t}\n\t\treturn res % mod;\n    }\n};\n```
[]