#C6551. Most Valuable Planet
Most Valuable Planet
Most Valuable Planet
You are given a set of planets where each planet produces various fruits over a day. For each planet, the production is represented as a list of integers. You are also given a list of integer values corresponding to the value of each type of fruit. The total value for a planet is computed using the formula: \(\text{value} = \sum_{i=1}^{m} (p_i \times f_i)\), where \(p_i\) is the production of the \(i\)-th fruit on that planet and \(f_i\) is the corresponding fruit value.
Your task is to determine the index (0-indexed) of the planet with the highest total value. In case of a tie, return the smallest index among those planets.
inputFormat
The input is read from standard input (stdin) and has the following format:
n m p11 p12 ... p1m p21 p22 ... p2m ... pn1 pn2 ... pnm f1 f2 ... fm
Here, n
is the number of planets and m
is the number of fruit types. Each of the following n
lines contains m
integers representing the production quantities of each fruit for that planet. The final line contains m
integers representing the value of each fruit.
outputFormat
The output is a single integer printed to standard output (stdout) — the index of the planet with the maximum total fruit value. In case of ties, the smallest index should be returned.
## sample3 3
3 2 1
1 1 10
4 0 0
2 3 8
1