<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:
    def maximumScore(self, nums: List[int], k: int) -> int:
        #这题题意挺拗口 意思是找一个subarray 起始点i和j之间要隔>=k
        #subarray[i,j] 中间要有尽可能大的min数
        #返回最大的这个min数*(j-i+1) 
        #好在解法直白 就是把左右双指针初始化在k上 然后往两边扩展 哪边数大 就先往哪边移动 跟踪计算
        l, r = k, k
        min_val = nums[k] 
        res = nums[k] 
         #【注意这里不能是>= <=】要在l,r走到nums首尾前一步 给下面的r+=1 l-=1留位置
         # 因为再往下一步就要取nums[l], nums[r]来比较
         # 如果不留位置 这取数就会取空
        while l > 0 or r < len(nums) -1:
            #错写成nums[r] > nums[l]--->要去看更远处一位的数字来比较 再移动指针取数
            if l == 0 or (r < len(nums) - 1 and nums[r+1] > nums[l-1]): 
                r += 1
            else:
                l -= 1
            min_val = min(min_val, nums[l], nums[r])
            res = max(res, min_val*(r-l+1))
        return res

917