Ternary search in array
Very easy
Execution time limit is 5 seconds
Runtime memory usage limit is 128 megabytes
Ternary search is a divide and conquer algorithm that can be used to find an element in an array. It is similar to binary search but in this algorithm, we divide the given array into three equal parts and determine which has the key (searched element).
Sorted array of integers is given. You must answer queries: whether the given number is in the array.
Input
First line contains two numbers and . Second line contains integers sorted in increasing order. Each of the next lines contains value of . The numbers in array do not exceed by absolute value.
Output
For each value of print on a separate line "YES" if is present in array and "NO" otherwise.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 1K
Acceptance rate 62%