nq1s788

бинарный поиск на массиве

Oct 18th, 2025
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. n = int(input())
  2. a = sorted(list(map(int, input().split())))
  3. x = int(input())
  4. l = -1 #не включительно, < x
  5. r = n #>= x
  6. while r - l > 1:
  7.     m = (r + l) // 2
  8.     if a[m] < x:
  9.         l = m
  10.     else:
  11.         r = m
  12. if r == n:
  13.     print('такого нет')
  14. else:
  15.     print(r)
Advertisement
Add Comment
Please, Sign In to add comment