9. Closest Products
Ограничения: время – 1s/2s, память – 64MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод
Послать решение Blockly Посылки Темы Где Обсудить (0)
Given is a set of integers and then a sequence of queries. A query gives you a number and asks to find a product of two distinct numbers from the set, which is closest to the query number.
The first line of input contains an integer `n\ (1<n≤1000)`, which indicates, how many numbers are in the set of integer. The next line contains n different numbers in increase order, separated by spaces. The next line contains a positive integer `m\ (0\ <\ m\ ≤\ 1000)` giving the number of queries. The next line contains a sequence integers, separated by spaces. All queries and products will be less than `10^9`.
Output should be organized as in the sample below. For each query output one line giving the query value and the closest product in the format as in the sample. Inputs will be such that no ties will occur.
Sample input
4
3 5 7 15
3
41 11 105
Sample output
Closest product to 41 is 45.
Closest product to 11 is 15.
Closest product to 105 is 105.