Searching an Array

View as PDF

Submit solution

Points: 100
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

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 \lceil \log_2(n) \rceil 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 (\le 10^{18}) 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 \le n \le 10^9
  • 1 \le k \le 10^{18}

Comments

There are no comments at the moment.