#K81097. Maximum Nutritional Value Recipe
Maximum Nutritional Value Recipe
Maximum Nutritional Value Recipe
In this problem, you are given the nutritional values for a set of ingredients and several recipes. Each recipe specifies a subset of ingredients (by their 1-indexed positions), and the nutritional value of a recipe is the sum of the nutritional values of its ingredients. Your task is to determine the recipe with the maximum nutritional value.
The nutritional value for a recipe is computed as: $$NV = \sum_{i \in recipe} a_i$$ where (a_i) is the nutritional value of the (i^{th}) ingredient.
inputFormat
The first line contains two integers (n) and (m) separated by a space, where (n) is the number of recipes and (m) is the number of ingredients. The second line contains (m) space-separated integers representing the nutritional values of the ingredients. This is followed by (n) lines, each describing a recipe. Each recipe starts with an integer (k) denoting the number of ingredients in that recipe, followed by (k) space-separated integers representing the 1-indexed positions of the ingredients.
outputFormat
Output a single integer, which is the maximum nutritional value among all the recipes.## sample
3 5
20 10 35 40 50
2 1 3
3 2 3 5
4 1 2 4 5
120