Maximum Subarray Min-Product
\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        int n = nums.size();\n        using ll = long long;\n        const int mod =
```\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& nums) {\n        int n = nums.size();\n        using ll = long long;\n        const int mod = 1e9 + 7;\n        vector<ll> nsl(n + 1), nsr(n + 1), pref(n + 1);\n        stack<ll> sk;\n        \n        for (int i = 0; i < n; i++) {\n            if (i == 0) {\n                pref[i] = nums[i];\n                continue;\n            }\n            pref[i] += pref[i - 1] + nums[i];\n        }\n        \n        for (int i = 0; i < n; i++) {\n            while (!sk.empty() && nums[i] < nums[sk.top()]) {\n                nsr[sk.top()] = i;\n                sk.pop();\n            }\n            sk.push(i);\n        }\n        while (!sk.empty()) {\n            nsr[sk.top()] = n;\n            sk.pop();\n        }\n        \n        while (!sk.empty()) sk.pop();\n        \n        for (int i = n - 1; i >= 0; i--) {\n            while (!sk.empty() && nums[i] < nums[sk.top()]) {\n                nsl[sk.top()] = i;\n                sk.pop();\n            }\n            sk.push(i);\n        }\n        while (!sk.empty()) {\n            nsl[sk.top()] = -1;\n            sk.pop();\n        }\n        \n        // for (int i = 0; i < n; i++)\n        //     cout << nsl[i] << \' \';\n        // cout << endl;\n        // for (int i = 0; i < n; i++)\n        //     cout << nsr[i] << " ";\n        // cout << endl;\n            \n        ll mx = 0;\n        for (int i = 0; i < n; i++) {\n            ll sum = pref[nsr[i] - 1] - (nsl[i] == -1 ? 0: pref[nsl[i]]);\n            ll val = nums[i] * sum;\n            mx = max(mx, val);\n        }\n        \n        return mx % mod;\n    }\n};\n```
[]