Simple Binary Search

This problem is for you to practice writing binary search code. Given N numbers, and K queries, determine if each query integer is present in the array.

Input format

The first line has two integers N and K. This is followed by N lines each containing exactly one integer for every element in the array to binary search on. These lines will be in non-decreasing order.

This is followed by K lines each containing one integer query each.

Output format

The output should contain exactly K lines. The ith line should be 'Y' (without quotes) if the ith query is present in the array, or 'N' otherwise.

Sample input

3 4
3
10
22
21
3
4
22

Sample Output

N
Y
N
Y

Editors note!

This is a very simple problem. You could easily solve it with standard programming libraries (std::binary_search, or std::map, or hash tables). It's here for practicing your programming skills, and so the main purpose is for you to try and code a binary search by hand. I'll put up more of these kind of problems if you like them.

CPU Timelimit: 1 seconds
Memory limit: 64M
Grading style: ioi
Register Now

Running Contests

Search the archive: