Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- nums = list(map(int, input().split()))
- def find(l, r):
- if l > r:
- return 0
- cur_max = 0
- max_index = 0
- cur_min = float('inf')
- min_index = 0
- for i in range(l, r+1):
- if nums[i] >= cur_max:
- cur_max = nums[i]
- max_index = i
- for j in range(l, max_index+1):
- if nums[j] < cur_min:
- cur_min = nums[j]
- min_index = j
- return 1 + find(l, min_index-1) + find(max_index+1, r)
- print(find(0, n-1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement