<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>

#pragma GCC optimize("O3")

array<int, 100001> left1, right1 ;
class Solution {
public:
    int maximumScore(vector<int>& nums, int k) {
        int N = nums.size() ;
        // vector<int> left1(N, -1) ;
        // vector<int> right1(N, N) ;

        for(int idx = 0 ; idx < N ; ++idx) {
            left1[idx] = idx - 1 ;
            while(left1[idx] != -1 && nums[left1[idx]] >= nums[idx]) {
                left1[idx] = left1[left1[idx]] ; 
            }
        }

        for(int idx = N-1; idx >= 0 ; --idx) {
            right1[idx] = idx + 1 ;
            while(right1[idx] != N && nums[right1[idx]] >= nums[idx]) {
                right1[idx] = right1[right1[idx]] ;
            }
        }

        int result = 0 ;
        for(int idx = 0 ; idx < N ; ++idx) {
            // int left1_idx = left1[idx] ;
            // int righ
            if(left1[idx] < k && k < right1[idx]) {

            int delta = right1[idx] - left1[idx] - 1 ;
            result = max(result, delta * nums[idx]) ;
            }


        }

        // for(auto idx : left1) {
        //     cout << idx << "  " ;
        // }
        // cout << endl ;


        // for(auto idx : right1) {
        //     cout << idx << "  " ;
        // }
        // cout << endl ;

        return result ;
    }
};
93200