nq1s788

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

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