#C601. Calculate Daily Water Requirement for a Field
Calculate Daily Water Requirement for a Field
Calculate Daily Water Requirement for a Field
You are given a rectangular field of crops with R rows and C columns. Each type of crop has an associated daily water requirement. Given the water requirement for each crop type and the layout of the field, compute the total water consumption needed per day.
Formally, let ( R ) and ( C ) denote the number of rows and columns, respectively. You are also given an integer ( N ) representing the number of distinct crop types. For each crop type, a string (the crop name) and an integer ( w ) (its water requirement) are provided. The field is then given as an ( R \times C ) grid, where each cell contains a crop name. Calculate the total water requirement by summing up the water requirement for each crop in the field.
inputFormat
The input is read from standard input (stdin) and is structured as follows:
Line 1: Two space-separated integers, ( R ) and ( C ), representing the number of rows and columns in the field. Line 2: An integer ( N ) representing the number of crop types. Next ( N ) lines: Each line contains a string and an integer separated by a space. The string is the crop name and the integer is its water requirement. Next ( R ) lines: Each line contains ( C ) space-separated strings representing the crop type for each cell in that row.
outputFormat
Output a single integer to standard output (stdout) representing the total water requirement for the entire field per day.## sample
3 3
3
rice 4
wheat 2
corn 3
rice wheat rice
wheat corn wheat
corn rice corn
27