Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- def find(a,k):
- def ispossible(m):
- @lru_cache()
- def find(i,j):
- n=len(a)
- if i==n:return False
- if j==k:return True
- else:
- if m>=a[i]:
- incl = find(i+1,j+1)
- excl = find(i+1,j)
- return incl or excl
- else:
- excl =find(i+1,j)
- return excl
- return find(0,0)
- l,r=min(a),max(a)
- ans = None
- while l<=r:
- m = (l+r)>>1
- if ispossible(m):
- ans = m
- r=m-1
- else:
- l=m+1
- return ans
- print(find([2,4,6,8,10],2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement