CF524C.The Art of Dealing with ATM

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most kk bills from it, and the bills may be of at most two distinct denominations.

For example, if a country uses bills with denominations 1010 , 5050 , 100100 , 500500 , 10001000 and 50005000 burles, then at k=20k=20 such ATM can give sums 100000100000 burles and 9600096000 burles, but it cannot give sums 9900099000 and 101000101000 burles.

Let's suppose that the country uses bills of nn distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash qq times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the qq of requests for cash withdrawal.

输入格式

The first line contains two integers nn , kk ( 1<=n<=50001<=n<=5000 , 1<=k<=201<=k<=20 ).

The next line contains nn space-separated integers aia_{i} ( 1<=ai<=1071<=a_{i}<=10^{7} ) — the denominations of the bills that are used in the country. Numbers aia_{i} follow in the strictly increasing order.

The next line contains integer qq ( 1<=q<=201<=q<=20 ) — the number of requests for cash withdrawal that you will make.

The next qq lines contain numbers xix_{i} ( 1<=xi<=21081<=x_{i}<=2·10^{8} ) — the sums of money in burles that you are going to withdraw from the ATM.

输出格式

For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print 1-1 , if it is impossible to get the corresponding sum.

输入输出样例

  • 输入#1

    6 20
    10 50 100 500 1000 5000
    8
    4200
    100000
    95000
    96000
    99000
    10100
    2015
    9950
    

    输出#1

    6
    20
    19
    20
    -1
    3
    -1
    -1
    
  • 输入#2

    5 2
    1 2 3 5 8
    8
    1
    3
    5
    7
    9
    11
    13
    15
    

    输出#2

    1
    1
    1
    2
    2
    2
    2
    -1
    
首页