#3. Binary Search
Binary Search
Background
Welcome to DSAI 2201, ^_^
Description
You are given a sorted integer array of length (non-decreasing), and then queries. For each query value :
- If exists in the array, output itself.
- If does not exist in the array, output the number in the array that is closest to .
- If two numbers are equally close, output the smaller one.
Format
Input
- The first line contains one integer ().
- The second line contains integers (non-decreasing, ).
- The third line contains integers (queries, ).
Output
Output integers, where the $i$-th integer is the answer to the -th query.
Samples
5
1 4 7 10 15
5 10 2 20 6
4 10 1 15 7
Limitation
1s, 128MiB for each test case.