✅ C++ || Monostack + Prefixsum || Explained with comments
Approach:\n Find the \'first next smallest\' and \'first prev smallest\' element index of every element of the given array using stack. Why? \n Because to find 
#### **Approach:**\n* Find the \'first next smallest\' and \'first prev smallest\' element index of every element of the given array using stack. Why? \n* Because to find the subarray in which a element is minimum is the subarray starts after its first previous minimum element and ends before its first next minimum element.\n* Now for every element find the required \'subarray left index\' as -> \'first prev smallest element\'s\' index of a element + 1.\n* And \'subarray right index\' as ->\'first next smallest element\'s\' index of a element - 1.\n* Calculate required subarray sum as ->prefix[right] - prefix[left-1] ( and prefix[right] only if left==0) for each element.\n* Finally Calculate Max min-product for each element and return the maximum ans%(1000000007).\n\n#### **CODE(with comments):**\n```\nclass Solution {\npublic:\n    #define M 1000000007\n    #define ll long long\n    \n    int maxSumMinProduct(vector<int>& nums) {\n        int n=nums.size();\n        \n        vector<int> prev_smallest(n); //prev. smallest ele idx for ith ele of nums\n        vector<int> next_smallest(n); //next smallest ele idx for ith ele of nums\n        vector<ll> prefix(n); // prefix sum to get the sum from any ith to jth idx\n        prefix[0]=nums[0];\n        \n        //calculate prefixSum\n        for(int i=1;i<n;i++){\n            prefix[i]=prefix[i-1]+ nums[i];\n        }\n        \n        stack<pair<int,int>> st1, st2; // st1->next smallest | st2->prev_smallest\n        st1.push({-1,n}); \n        st2.push({-1,-1});\n        \n        //find next_smallest\'s element index for every ele of nums\n        for(int i=n-1;i>=0;i--){\n            while(!st1.empty() && st1.top().first>=nums[i]){\n                st1.pop();\n            }\n            \n            next_smallest[i]=st1.top().second;\n            st1.push({nums[i],i});\n        }\n        \n        //find prev_smallest\'s element index for every ele of nums\n        for(int i=0;i<n;i++){\n            while(!st2.empty() && st2.top().first>=nums[i]){\n                st2.pop();\n            }\n            \n            prev_smallest[i]=st2.top().second; //index\n            st2.push({nums[i],i});\n        }\n        \n        ll ans=INT_MIN; \n        \n        //calculate max min-product\n        for(int i=0;i<n;i++){\n        // as we have stored the index -1 ->if no prev smallest,\n        // and index n ->if no next smallest.    \n            \n            int left=prev_smallest[i]+1; //left index of subarray \n            int right=next_smallest[i]-1; //right index of subarray \n            \n            //find subarray sum using prefix sum\n            ll subArraySum= left==0 ? prefix[right] : (prefix[right]-prefix[left-1]);\n            \n            //take the max min-product everytime\n            ans=max(ans, nums[i]*subArraySum);\n        }\n        \n        return ans%M;\n    }\n};\n```\n\n#### Upvote, if you like it :)\n
['Stack', 'C', 'Monotonic Stack', 'Prefix Sum']