Coins and Queries
Ira has a collection of n coins, each with a denomination represented by a[i]
. It is guaranteed that each denomination is a natural power of 2, meaning a[i]
= 2^d
, where 0 ≤ d.
Ira needs to answer q queries. Each query is defined by an integer b[j]
. The task is to determine the minimum number of coins required to achieve the sum b[j]
using Ira's coins. If it is not possible to form the sum b[j]
, the answer for that query should be -1.
Note that answering a query does not alter the collection of coins Ira possesses.
Input
The first line contains two integers n and q (1 ≤ n, q ≤ 2·10^5
) – representing the number of coins and the number of queries, respectively.
The second line lists n integers a[1]
, a[2]
, ..., a[n]
(1 ≤ a[i]
≤ 2·10^9
) – these are the denominations of the coins.
The following q lines each contain a single integer b[j]
(1 ≤ b[j]
≤ 10^9
) – representing each query.
Output
Output q integers ans[j]
, where the j-th integer is the answer to the j-th query.