java dp-Solution
java code is:\n# \n\nclass Solution {\n    long find(long arr[],int l,int r){\n        return arr[r]-(l-1>=0 ? arr[l-1] : 0);\n    }\n    public int maxSumMinPr
java code is:\n# \n```\nclass Solution {\n    long find(long arr[],int l,int r){\n        return arr[r]-(l-1>=0 ? arr[l-1] : 0);\n    }\n    public int maxSumMinProduct(int[] nums) {\n        int n=nums.length;\n       long preSum[]=new long[n];\n       for(int i=0;i<n;i++)\n           preSum[i]=nums[i]+(i-1>=0 ? preSum[i-1] : 0 );\n        Stack<Integer>stack=new Stack<>();\n        int arr[][]=new int[n][2];\n        //to-find how long we can expand it in left\n        for(int i=0;i<n;i++){\n            while(!stack.isEmpty()&&nums[stack.peek()]>=nums[i])stack.pop();\n            arr[i][0]=stack.isEmpty() ? -1 : stack.peek();\n            stack.push(i);\n        }\n        stack=new Stack<>();\n        //to-find hoe long we can expand it in right;\n        for(int i=n-1;i>=0;i--){\n             while(!stack.isEmpty()&&nums[stack.peek()]>=nums[i])stack.pop();\n            arr[i][1]=stack.isEmpty() ? n : stack.peek();\n            stack.push(i);\n        }\n        long res=0;\n        for(int i=0;i<n;i++){\n            res=Math.max(res,nums[i]*find(preSum,arr[i][0]+1,arr[i][1]-1));\n        }\n        return (int)(res%(1000000007));\n    }\n}\n\n```\n***Please,Upvote if this is helpful***
[]