最近数

Background

Look, look, look, find a recent number ...

找呀找,找呀找,找到一个最近数……

Description

Given a sequence, find the element closest to the given value.

给定一个序列,查找和给定值最接近的元素。

Format

Input

The first row contains an integer n, which is the sequence length. 1 <= n <= 100000。 The second row contains n integers, which are elements of the sequence. All elements are between 0-1,000,000,000 in size. The third line contains an integer m, which is the number of given values to be inquired. 1 <= m <= 10000。 The next M lines, one integer per line, are the given values of the closest elements to be queried. All given values are between 0-1,000,000,000.

第一行包含一个整数n,为序列长度。1 <= n <= 100000。
第二行包含n个整数,为序列各元素。所有元素的大小均在0-1,000,000,000之间。
第三行包含一个整数m,为要询问的给定值个数。1 <= m <= 10000。
接下来m行,每行一个整数,为要询问最接近元素的给定值。所有给定值的大小均在0-1,000,000,000之间。

Output

M rows, one integer per row, are the element values closest to the corresponding given values, and the input order is maintained. If more than one value satisfies the condition, the output is the smallest one.

共m行,每行一个整数,为最接近相应给定值的元素值,保持输入顺序。若有多个值满足条件,输出最小的一个。

Sample 1

Input

3
2 5 8
2
10
5

Output

8
5

Limitation

对于30%的测试数据,n*m<=10000;
对于100%测试数据见输入格式。

Source

Amorphophallus Orz Group

信息

ID
1021
难度
3
分类
队列 点击显示
标签
递交数
11
已通过
2
通过率
18%
上传者

相关

在下列训练计划中:

AOG题库训练计划