Searching an Array
Your friend has a sorted array of n integers, and he wants you to find whether it contains a number k. You can make a maximum of ⌈log2(n)⌉ queries of the following form:
- What is the number at the x-th position? (1 indexed).
Interaction
The first line of input contains two integers, n and k.
To query the number at the x-th position, print a line containing only x and the judge will respond with the number (≤1018) at that position, which you can read as a line of input.
To give a final answer, print "YES" or "NO", answering whether the integer exists in the array.
Constraints
- 1≤n≤109
- 1≤k≤1018
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.