-
Notifications
You must be signed in to change notification settings - Fork 0
/
1793.py
44 lines (39 loc) · 1.29 KB
/
1793.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution:
def maximumScore(self, nums: List[int], k: int) -> int:
min_value = nums[k]
length = 1
max_result = min_value * length
pre = nums[:k]
pro = nums[k+1:]
count1 = k-1
count2 = 0
while length < len(nums):
if count1 >= 0:
while count1 >= 0 and pre[count1] >= min_value:
count1 -= 1
length += 1
if count1 <= -1:
break
if count2 < len(pro):
while count2 <= len(pro)-1 and pro[count2] >= min_value:
count2 += 1
length += 1
if count2 >= len(pro):
break
max_result = max(min_value * length, max_result)
if count1 <= 0:
left = -1
else:
left = pre[count1]
if count2 >= len(pro)-1:
right = -1
else:
right = pro[count2]
if left > right:
min_value = min(min_value,left)
count1 -= 1
if left <= right:
min_value = min(min_value,right)
count2 += 1
length += 1
return max_result