#K39917. Minimum Vehicles Required
Minimum Vehicles Required
Minimum Vehicles Required
You are given a certain number of friends and a list of available vehicles with their capacities. Your task is to determine the minimum number of vehicles required so that the total capacity is at least equal to the number of friends.
In mathematical terms, given a sorted (in descending order) list of capacities \(c_1, c_2, \dots, c_M\) and a number \(N\) (friends), determine the smallest integer \(k\) such that \[ \sum_{i=1}^{k} c_i \ge N \] If no such \(k\) exists, output -1.
The program should read from standard input (stdin) and print results to standard output (stdout). Each test case should be processed independently.
inputFormat
The input starts with an integer \(T\) representing the number of test cases. Each test case consists of two lines:
- The first line contains two integers \(N\) and \(M\) where \(N\) is the number of friends and \(M\) is the number of available vehicles.
- The second line contains \(M\) space-separated integers representing the capacities of the vehicles.
outputFormat
For each test case, output a single integer on a new line — the minimum number of vehicles required. If it is not possible to accommodate all friends, output -1.
## sample2
7 3
2 3 5
10 2
3 4
2
-1
</p>