CF1003D.Coins and Queries

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp has nn coins, the value of the ii -th coin is aia_i . It is guaranteed that all the values are integer powers of 22 (i.e. ai=2da_i = 2^d for some non-negative integer number dd ).

Polycarp wants to know answers on qq queries. The jj -th query is described as integer number bjb_j . The answer to the query is the minimum number of coins that is necessary to obtain the value bjb_j using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value bjb_j , the answer to the jj -th query is -1.

The queries are independent (the answer on the query doesn't affect Polycarp's coins).

输入格式

The first line of the input contains two integers nn and qq ( 1n,q21051 \le n, q \le 2 \cdot 10^5 ) — the number of coins and the number of queries.

The second line of the input contains nn integers a1,a2,,ana_1, a_2, \dots, a_n — values of coins ( 1ai21091 \le a_i \le 2 \cdot 10^9 ). It is guaranteed that all aia_i are integer powers of 22 (i.e. ai=2da_i = 2^d for some non-negative integer number dd ).

The next qq lines contain one integer each. The jj -th line contains one integer bjb_j — the value of the jj -th query ( 1bj1091 \le b_j \le 10^9 ).

输出格式

Print qq integers ansjans_j . The jj -th integer must be equal to the answer on the jj -th query. If Polycarp can't obtain the value bjb_j the answer to the jj -th query is -1.

输入输出样例

  • 输入#1

    5 4
    2 4 8 2 4
    8
    5
    14
    10
    

    输出#1

    1
    -1
    3
    2
    
首页