#P333. 练56.2 查找最接近的元素
练56.2 查找最接近的元素
Description
In a non-decreasing sequence, find the element closest to a given value.
Input Format
The first line contains an integer , representing the length of the non-decreasing sequence. .
The second line contains integers, representing the elements of the non-decreasing sequence. All elements are between and .
The third line contains an integer , representing the number of queries. .
The next lines each contain an integer, representing the given value for which the closest element is to be found. All given values are between and .
Output Format
lines, each containing an integer representing the element closest to the corresponding given value, maintaining the input order. If multiple values satisfy the condition, output the smallest one.
Sample
3
2 5 8
2
10
58
5