#K11061. Taco Dish Selection
Taco Dish Selection
Taco Dish Selection
Asha loves making tacos, but with a twist: she wants to maximize the leftover ingredients. Given several test cases, each provides the total number of available ingredients X, the number of dishes Y, and a list Z of required ingredients for each dish. Your task is to help Asha choose the dish that not only she can make (i.e. the dish’s ingredient requirement is less than or equal to X) but also maximizes the remaining ingredients (X - Z[i]). In case of multiple options, choose the dish that appears first among those that yield the maximum remainder. Formally, for each test case, you need to find the smallest index i (1-indexed) such that ( Z_i \le X ) and ( X - Z_i ) is maximized. If no dish can be prepared, output -1.
inputFormat
The input is given via standard input (stdin). The first line contains an integer T, the number of test cases. Each test case is described in two lines. The first line of each test case contains two space-separated integers: X (the number of available ingredients) and Y (the number of dishes). The second line contains Y space-separated integers where the i-th integer represents the number of ingredients required to prepare the i-th dish.
outputFormat
For each test case, output a single line containing one integer: the 1-indexed position of the dish that Asha should prepare in order to maximize the leftover ingredients. If none of the dishes can be made, output -1.## sample
2
10 3
8 5 6
5 2
7 3
2
2
</p>