<p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>

<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <code>i &lt;= k &lt;= j</code>.</p>

<p>Return <em>the maximum possible <strong>score</strong> of a <strong>good</strong> subarray.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,4,3,7,4,5], k = 3
<strong>Output:</strong> 15
<strong>Explanation:</strong> The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15. 
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [5,5,4,5,4,1,1,1], k = 0
<strong>Output:</strong> 20
<strong>Explanation:</strong> The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 2 * 10<sup>4</sup></code></li>
	<li><code>0 &lt;= k &lt; nums.length</code></li>
</ul>

class Solution {
public:
vector<int>nse(vector<int >&nums){
stack<int>st;
int i;
int n=nums.size();
vector<int>ans(n);
for(i=n-1;i>=0;i--){
    while(!st.empty()&&nums[st.top()]>=nums[i]){
        st.pop();
    }
    if(st.empty()){
ans[i]=n-1;
    }
    else{
        ans[i]=st.top()-1;
    }
st.push(i);
}
return ans;
}
vector<int>pse(vector<int >&nums){
stack<int>st;
int i;
int n=nums.size();
vector<int>ans(n);
for(i=0;i<n;i++){
    while(!st.empty()&&nums[st.top()]>=nums[i]){
        // cout<<nums[i]<<" "<<st.top()<<endl;
        st.pop();
    }
    if(st.empty()){
ans[i]=0;
    }
    else{
        ans[i]=st.top()+1;
    }
st.push(i);
}
return ans;
}
    int maximumScore(vector<int>& nums, int k) {
        int n=nums.size();
        vector<int>ns= nse(nums);
        vector<int>ls=pse(nums);
        // for(auto it:ns) cout<<it<<" ";
        // cout<<endl;
        // for(auto it:ls) cout<<it<<" ";
        int ans=0;
        int  i;
        for(i=0;i<n;i++){
            int j=(ns[i]);
            int l= (ls[i]);
            if((l)<=k&&(j)>=k){
                     j=max(ns[i],k);
             l= min(ls[i],k);
                int p=abs(j-l+1)*nums[i];
                cout<<p<<" " <<i<<endl;
                ans=max(ans,p);
            }
        }
        return ans;
        
    }
};
103600