#P17475. [ICPC 2018 Jiaozuo R] Carpets Removal
[ICPC 2018 Jiaozuo R] Carpets Removal
Problem Description
Mike's living room is covered by square tiles. These tiles form a grid in which rows are numbered with through from top to bottom and columns are numbered with through from left to right.
:::align{center}
:::
Above these tiles on the floor are laying rectangular carpets whose sides are parallel to sides of the grid. Each carpet covers the intersection of several consecutive rows and several consecutive columns, forming a rectangle. Precisely speaking, the -th carpet of them is described by four integers with and , indicating that the carpet covers all tiles which are both ranged from the -th row to the -th row and ranged from the -th column to the -th column.
Now Mike asks you to take away exactly two carpets of them, in order to minimize the number of tiles that would still be covered by at least one remaining carpet.
The figure provided above describes the sample case, in which those two rectangular regions with imaginary boundaries indicate an optimal removal of two carpets.
Input Format
The input contains several test cases, and the first line contains a positive integer indicating the number of test cases which is up to .
For each test case, the first line contains two integers and indicating the number of carpets and the number of tiles in each row or column, where and .
Each of the following lines contains four integers , , , describing a carpet laying on the floor and its postion, where and .
We guarantee that the sum of in all test cases is up to , while the sum of in all test cases is up to .
Output Format
For each test case, output a line containing the minimum number of tiles that would still be covered by at least one remaining carpet after removal of two carpets.
1
4 5
1 1 3 3
2 2 4 4
3 3 5 5
2 3 1 4
2