#C4878. Maximizing the Number of Taco Dishes
Maximizing the Number of Taco Dishes
Maximizing the Number of Taco Dishes
You are given an initial number of ingredients and a set of dishes that can be cooked. Each dish requires a specified number of ingredients and, after cooking, yields some ingredients back. Your task is to determine the maximum number of dishes that can be cooked under optimal conditions.
For each dish, you are given two integers: the number of ingredients required (\( a \)) and the number of ingredients gained after cooking (\( b \)). When you choose to cook a dish, your remaining ingredients decrease by \( a - b \). You may cook the dishes in any order you choose, but each dish can only be cooked once. The goal is to cook as many dishes as possible.
Hint: A greedy approach that prioritizes dishes with smaller net cost \( (a - b) \) may be effective.
inputFormat
The first line contains an integer \( T \) representing the number of test cases.
For each test case, the first line contains two integers: \( X \) (the initial number of ingredients) and \( N \) (the number of available dishes).
This is followed by \( N \) lines, each containing two integers \( a \) and \( b \) representing the number of ingredients required to cook the dish and the number of ingredients gained after cooking, respectively.
All input values are provided via standard input.
outputFormat
For each test case, output a single line containing the maximum number of dishes that can be cooked.
The output should be printed to standard output.
## sample2
10 2
8 0
4 2
5 1
10 0
2
0
</p>