#K33327. Maximum Value in a Grid

    ID: 25063 Type: Default 1000ms 256MiB

Maximum Value in a Grid

Maximum Value in a Grid

You are given a grid with n rows and m columns. Initially, each cell of the grid has a value of 0. You are then given k operations. Each operation is described by four integers a, b, c, and d and indicates that every cell in the sub-grid defined by the top-left cell (a, b) and bottom-right cell (c, d) should be incremented by 1.

Your task is to determine the maximum value in the grid after performing all operations, and count how many cells in the grid have this maximum value.

Mathematically, if the grid is represented as \(G[i][j]\), and an operation is applied for all \(i, j\) such that \(a \leq i \leq c\) and \(b \leq j \leq d\), then after all operations, you need to find:

[ \text{maxValue} = \max_{1 \leq i \leq n,; 1 \leq j \leq m} G[i][j] ]

[ \text{maxCount} = #{ (i, j) : G[i][j] = \text{maxValue} } ]

inputFormat

The input is read from standard input and has the following format:

  • First line contains three integers: n m k, representing the number of rows, columns and the number of operations.
  • The next k lines each contain four integers: a b c d, describing an operation that increments all cells in the sub-grid from (a, b) to (c, d).

outputFormat

Output to standard output two integers separated by a space: the maximum value in the grid and the number of cells with that value.

## sample
4 4 2
1 1 3 3
2 2 4 4
2 4