[C++] A follow-up of standard Histogram area problem
This is the followup of standard largest area rectangle in histogram problem (https://leetcode.com/problems/largest-rectangle-in-histogram/)\nOnly change to be 
This is the followup of standard largest area rectangle in histogram problem (https://leetcode.com/problems/largest-rectangle-in-histogram/)\nOnly change to be done is in last \'for loop\' where we have to take the sum of the rectangular bars to be included instead of just taking width of the rectangle.\n\nLets say you have array 2 1 3 4 7 2 5. You need to calculate to each nums[i] the size of its window such that it is the smallest element. So the window sizes are as follows: 1 7 3 2 1 4 1. This can be calculated using the method shown in histogram problem or use two arrays Left and Right (which I prefer) to find smallest element on the right and left of a number at index I. Then use prefix sums to find max over all elements.\n(Thanks @amk1214 for the explanation)\n\n*DO UPVOTE if you fnd it helpful!!*\n\n```\nclass Solution {\npublic:\n    int maxSumMinProduct(vector<int>& heights) {\n        const unsigned int M = 1000000007;\n        vector<int> left,right;\n        stack<pair<int,int>> s;\n        int n=heights.size();\n        for(int i=n-1;i>=0;i--){\n            if(s.size()==0) right.push_back(n);\n            else if(s.size()>0 && s.top().first<heights[i]) right.push_back(s.top().second);\n            else if(s.size()>0 && s.top().first>=heights[i]){\n                while(s.size()>0 && s.top().first>=heights[i]) s.pop();\n                if(s.size()==0) right.push_back(n);\n                else right.push_back(s.top().second);\n            }\n            s.push({heights[i],i});\n        }\n        reverse(right.begin(), right.end());\n        \n        stack<pair<int,int>> s1;\n        for(int i=0;i<n;i++){\n            if(s1.size()==0) left.push_back(-1);\n            else if(s1.size()>0 && s1.top().first<heights[i]) left.push_back(s1.top().second);\n            else if(s1.size()>0 && s1.top().first>=heights[i]){\n                while(s1.size()>0 && s1.top().first>=heights[i]) s1.pop();\n                if(s1.size()==0) left.push_back(-1);\n                else left.push_back(s1.top().second);\n            }\n            s1.push({heights[i],i});\n        }\n        long long int area=0;\n        vector<long long int> sum(n,0);\n        sum[0]=heights[0]%M;\n        for(int i=1;i<n;i++){\n            sum[i]= (sum[i-1] +heights[i]);\n            // sum[i]%=M;\n            // cout<<sum[i]<<" ";\n        }\n        // cout<<endl;\n        for(int i=0;i<n;i++){\n            // cout<<right[i]<<" "<<left[i]<<"   ";\n            long long int s;\n            if(left[i]==-1) s=0;\n            else s=sum[left[i]];\n            long long int curr= (heights[i] *(sum[right[i]-1]-s));\n            // int curr=0;\n            area = max(area,curr);\n            // area=area%M;\n        }\n        // cout<<endl;\n        return area%M;\n    }\n};\n```
[]