#C2846. Minimum Value in Grid After Operations
Minimum Value in Grid After Operations
Minimum Value in Grid After Operations
You are given an N × M grid that is initially filled with zeros. You are then given Q operations. Each operation is described by four integers \(x_1\), \(y_1\), \(x_2\), \(y_2\) which denote the top-left and bottom-right coordinates (1-indexed) of a subgrid. For each such operation, increment each cell in the subgrid by one.
After performing all operations, output the minimum value among all cells in the grid.
Note: If a cell is not affected by any operation, its value remains 0. It can be proven that the final minimum value is equal to the number of operations that impact every cell of the grid.
inputFormat
The input is read from stdin and has the following format:
- The first line contains three integers \(N\), \(M\), and \(Q\), representing the number of rows, columns, and operations respectively.
- The next \(Q\) lines each contain four integers: \(x_1\), \(y_1\), \(x_2\), \(y_2\), which represent an operation on the subgrid spanning from row \(x_1\) to \(x_2\) and column \(y_1\) to \(y_2\) (inclusive).
outputFormat
Output to stdout a single integer, which is the minimum value found in the grid after all operations have been performed.
## sample3 3 3
1 1 2 2
2 2 3 3
1 1 3 3
1