stack with 100% faster
class Solution {\npublic:\n    int mod=1000000007;\n    int maxSumMinProduct(vector& nums) {\n                    int n=nums.size();\n                  stacks1,
class Solution {\npublic:\n    int mod=1000000007;\n    int maxSumMinProduct(vector<int>& nums) {\n                    int n=nums.size();\n                  stack<int>s1,s2;\n                  vector<long long>prefix(n),suffix(n);\n                  for(int i=0;i<n;i++){\n                       while(!s1.empty()&&nums[s1.top()]>=nums[i])\n                           s1.pop();\n                      if(!s1.empty())\n                          prefix[i]=s1.top();\n                      else\n                          prefix[i]=-1;\n                      s1.push(i);\n                  }\n                  for(int i=n-1;i>=0;i--){\n                       while(!s2.empty()&&nums[s2.top()]>=nums[i])\n                           s2.pop();\n                      if(!s2.empty())\n                          suffix[i]=s2.top();\n                      else\n                          suffix[i]=n;\n                      s2.push(i);\n                  }\n                  vector<long long int>prefix1(n);\n                  prefix1[0]=nums[0];\n                  for(int i=1;i<n;i++){\n                      long long int a=(prefix1[i-1]+nums[i]);\n                      prefix1[i]=a;\n                    //  cout<<prefix\n                  }\n                 long long int max1=LONG_MIN;\n                 for(int i=0;i<n;i++){\n                      long long int a;\n                      if(prefix[i]!=-1)\n                          a=(prefix1[suffix[i]-1]-prefix1[prefix[i]]);\n                      else\n                          a=(prefix1[suffix[i]-1]);\n                      long long int b=((nums[i])*(a));\n                      max1=max(max1,b);\n                    //  cout<<suffix[i]<<" "<<prefix[i]<<" "<<b<<" "<<a<<endl;\n                 }\n         return max1%mod;\n    }\n};
[]