CF1303D.Fill The Bag

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You have a bag of size nn . Also you have mm boxes. The size of ii -th box is aia_i , where each aia_i is an integer non-negative power of two.

You can divide boxes into two parts of equal size. Your goal is to fill the bag completely.

For example, if n=10n = 10 and a=[1,1,32]a = [1, 1, 32] then you have to divide the box of size 3232 into two parts of size 1616 , and then divide the box of size 1616 . So you can fill the bag with boxes of size 11 , 11 and 88 .

Calculate the minimum number of divisions required to fill the bag of size nn .

输入格式

The first line contains one integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases.

The first line of each test case contains two integers nn and mm ( 1n1018,1m1051 \le n \le 10^{18}, 1 \le m \le 10^5 ) — the size of bag and the number of boxes, respectively.

The second line of each test case contains mm integers a1,a2,,ama_1, a_2, \dots , a_m ( 1ai1091 \le a_i \le 10^9 ) — the sizes of boxes. It is guaranteed that each aia_i is a power of two.

It is also guaranteed that sum of all mm over all test cases does not exceed 10510^5 .

输出格式

For each test case print one integer — the minimum number of divisions required to fill the bag of size nn (or 1-1 , if it is impossible).

输入输出样例

  • 输入#1

    3
    10 3
    1 32 1
    23 4
    16 1 4 1
    20 5
    2 1 16 1 8

    输出#1

    2
    -1
    0
首页