Advertisement
nq1s788

бинарный поиск

Apr 4th, 2024
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. a = list(map(int, input().split()))
  2. n = len(a)
  3. x = int(input()) #найти индекс первого >= x
  4. l = -1 #не подходят
  5. r = n #подходят
  6. while r - l > 1:
  7.     m = (l + r) // 2
  8.     if a[m] >= x:
  9.         r = m
  10.     else:
  11.         l = m
  12. print(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement