Advertisement
serega1112

cipher - bruteforce

Dec 28th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1.  
  2. n = int(input())
  3. nums = list(map(int, input().split()))
  4.  
  5.  
  6. def find(l, r):
  7.     if l > r:
  8.         return 0
  9.     cur_max = 0
  10.     max_index = 0
  11.     cur_min = float('inf')
  12.     min_index = 0
  13.     for i in range(l, r+1):
  14.         if nums[i] >= cur_max:
  15.             cur_max = nums[i]
  16.             max_index = i
  17.     for j in range(l, max_index+1):
  18.         if nums[j] < cur_min:
  19.             cur_min = nums[j]
  20.             min_index = j
  21.     return 1 + find(l, min_index-1) + find(max_index+1, r)
  22.  
  23. print(find(0, n-1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement