#K6061. Minimum Food Items
Minimum Food Items
Minimum Food Items
You are given a pet's dietary requirements expressed as two integers \(P\) and \(C\) which represent the required amounts of protein and carbohydrates respectively. In addition, you have access to \(K\) food items, each providing a specific amount of protein and carbohydrates.
Your task is to determine the minimum number of food items needed to exactly meet the pet's nutritional requirements. In other words, you must select a combination of food items such that the total protein equals \(P\) and the total carbohydrates equals \(C\). If it is not possible to achieve the exact nutritional values, output -1.
Note: You may use the same food item multiple times. The answer is the minimum number of food items required.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer \(T\), representing the number of test cases.
- For each test case:
- The first line contains two space-separated integers \(P\) and \(C\), the required amounts of protein and carbohydrates.
- The second line contains an integer \(K\), the number of available food items.
- The following \(K\) lines each contain two space-separated integers indicating the protein and carbohydrate content provided by a food item.
outputFormat
For each test case, output a single line to standard output (stdout) containing the minimum number of food items required to meet the exact nutritional requirements. If it is impossible, output -1.
## sample2
8 12
2
4 6
2 3
7 10
2
5 5
3 2
2
-1
</p>