#K41757. Find Maximum in a Grid after Operations

    ID: 26936 Type: Default 1000ms 256MiB

Find Maximum in a Grid after Operations

Find Maximum in a Grid after Operations

You are given a grid with n rows and m columns, initially filled with zeroes. You need to perform q operations. Each operation adds a given integer value to all the cells of either a particular row or a particular column.

Each operation is given in the form:

(type, index, value)(type,\ index,\ value)
  • If type is row, the operation adds value to all cells in the index-th row.
  • If type is col, the operation adds value to all cells in the index-th column.

After all operations, the value at cell (i, j) becomes the sum of the additions for row i and column j. The answer is the maximum value in the grid, which can be derived as follows:

$$max\_value = \max_{1 \leq i \leq n,\ 1 \leq j \leq m}\ (row[i] + col[j]) $$

Your task is to compute and output this maximum value.

inputFormat

The first line of input contains three integers n, m and q separated by spaces, denoting the number of rows, columns, and operations respectively.

Each of the next q lines contains an operation in the format:

type index value

where type is either row or col, index is the 1-indexed row or column number, and value is the integer to add.

outputFormat

Output a single integer denoting the maximum value present in the grid after all operations.

## sample
3 3 5
row 1 1
col 2 -1
row 3 5
col 3 3
row 1 2
8

</p>