#K8286. Maximum Value in Grid After Subgrid Increments

    ID: 36069 Type: Default 1000ms 256MiB

Maximum Value in Grid After Subgrid Increments

Maximum Value in Grid After Subgrid Increments

You are given a grid with n rows and m columns initially filled with zeros. You will perform k operations. Each operation is defined by four integers r1, c1, r2, c2 (0-indexed) that represent the top-left and bottom-right corners of a subgrid. In each operation, every cell in the subgrid is incremented by 1.

Your task is to determine the maximum value in the grid after all operations have been applied.

The problem can be described mathematically as follows:

$$\text{grid}_{ij} = \sum_{\text{op}=1}^{k} \mathbf{1}_{\{r1_{op} \le i \le r2_{op} \, \wedge\, c1_{op} \le j \le c2_{op}\}} $$

and you need to output the value:

$$\max_{0 \le i < n,\; 0 \le j < m} \; \text{grid}_{ij} $$

inputFormat

The first line of input contains three space-separated integers: n m k, where:

  • n is the number of rows in the grid,
  • m is the number of columns in the grid,
  • k is the number of operations.

Each of the next k lines contains four space-separated integers r1 c1 r2 c2 representing an operation that increments each cell in the subgrid from (r1, c1) to (r2, c2) (both inclusive). The grid uses 0-indexing.

outputFormat

Output a single integer, which is the maximum value in the grid after performing all the operations.

## sample
3 3 1
0 0 2 2
1

</p>