Matrix Game
InterviewTime limit1sMemory limit2048 MB
For each column, pick the row that maximizes |a - b| there, then sum those maxima over all M columns Chan calls to get the largest possible Diff.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
Hun and Chan are playing a matrix game. Each has an matrix, and .
The game has rounds. In each round, Hun and Chan call out the numbers and at the same time. Here and are integers between 1 and . Hun scores points and Chan scores points.
Last night Hun dreamed the numbers that Chan will call in the rounds. Hun can therefore choose numbers that maximize Diff. Diff is defined as , the sum over all rounds of the absolute difference between the two players' scores in that round.
Given the numbers Chan calls in each round, write a program that outputs the maximum possible value of Diff when Hun chooses his numbers to maximize it.
Input
The first line contains two integers and (, ). is the size of each player's matrix, and is the number of rounds.
The next lines contain Hun's matrix , where line holds the values of row . The following lines contain Chan's matrix in the same way. All matrix values are integers between 0 and 1,000.
The last line contains integers between 1 and , the numbers Chan calls in each round.
Output
Print the maximum value of Diff when Hun chooses his numbers to maximize it.