#K6211. Can Prepare Recipes

    ID: 31459 Type: Default 1000ms 256MiB

Can Prepare Recipes

Can Prepare Recipes

You are given several recipes and a list of available ingredients with their quantities. Each recipe requires certain ingredients in specified amounts. Your task is to determine which recipes can be fully prepared with the available ingredients.

For each recipe, if for every required ingredient the available quantity is at least as much as required, then that recipe can be prepared. Output the indices (0-indexed) of all recipes that can be fully prepared, separated by spaces. If no recipe can be prepared, output an empty line.

The check is made exactly as described by the following criterion: For each ingredient in recipe i with required quantity \(r_{i}\), if the available ingredient quantity \(a_{i}\) is less than \(r_{i}\), then recipe i cannot be prepared. Otherwise, it is valid.

Note: Input will be given through standard input (stdin) and output must be written to standard output (stdout).

inputFormat

The input is given in the following format:

 n
 r1 ingredient_count ingredient1 quantity1 ingredient2 quantity2 ...
 r2 ingredient_count ingredient1 quantity1 ingredient2 quantity2 ...
 ...
 m
 available_ingredient_1 available_quantity_1
 available_ingredient_2 available_quantity_2
 ...
  • The first line contains an integer n, the number of recipes.
  • The next n lines each start with an integer representing the number of ingredients in the recipe, followed by that many pairs of an ingredient name (string) and its required quantity (integer).
  • The next line contains an integer m, the number of available ingredients.
  • The following m lines each contain an ingredient name (string) and its available quantity (integer).

outputFormat

Output a single line containing the indices (0-indexed) of the recipes that can be fully prepared, separated by a single space. If no recipe can be prepared, print an empty line.

## sample
2
2 flour 100 sugar 50
2 flour 100 butter 50
3
flour 200
sugar 50
butter 50
0 1