#K14056. Temperature Grid Updates

    ID: 24049 Type: Default 1000ms 256MiB

Temperature Grid Updates

Temperature Grid Updates

You are given a temperature grid of dimensions \(n \times m\) and an addend grid of the same dimensions. Initially, each cell \(a_{ij}\) of the grid is given by an integer value from the initial matrix. You are then provided with an addend matrix where each cell \(b_{ij}\) indicates the amount to add to the corresponding cell in the temperature grid at each update.

After applying exactly \(t\) updates, the value at cell \((i,j)\) becomes:

[ a_{ij} + t \times b_{ij} ]

Your task is to determine the maximum temperature observed in the grid after \(t\) updates. Under the assumption that the maximum final temperature can be computed by selecting the maximum value from the initial matrix and adding \(t\) times the maximum value from the addend matrix, your answer will be:

[ \text{max}{i,j},a{ij} + t \times \text{max}{i,j},b{ij} ]

</p>

Note: Although the above formula may not always equal \(\max_{i,j}(a_{ij}+t\,b_{ij})\) for arbitrary matrices, it is the intended method for this problem.

inputFormat

The input is given via standard input (stdin) with the following format:

n m t
a11 a12 ... a1m
...
an1 an2 ... anm
b11 b12 ... b1m
...
bn1 bn2 ... bnm

Here:

  • \(n\) and \(m\) are the number of rows and columns of the matrices respectively.
  • \(t\) is the number of updates.
  • The next \(n\) lines represent the initial temperature grid (initial matrix).
  • The following \(n\) lines represent the addend grid (addend matrix).

outputFormat

Output a single integer on standard output (stdout) — the maximum temperature observed after \(t\) updates, computed as \(\max(a_{ij}) + t \times \max(b_{ij})\).

## sample
3 3 2
1 2 3
4 5 6
7 8 9
1 1 1
1 1 1
1 1 1
11