Maximum Irrigation

0

0 votes
Medium, Prefix sum
Problem

There is a group of n farmers in Jaipur, who are planing to irrigate their plot of productive land. Every farmer can irrigate his plot of land, which is in the shape of a rectangle, whose bottom left and upper right corner coordinates are given (rectangle is aligned parallelly to coordinate axes). It is also given that more than one farmer can share a piece of land. But due to hot and dry climate during summers, land is very deficient of water, so to completely irrigate a piece of land, at least n - 1 farmers must irrigate this land (this piece of land must be common to at least n - 1 farmers). Note that one farmer must irrigate his land only once.
Now your task is to find out the plot of land with maximum area which gets completely irrigated.

 

Input:
The first line contains a single integer T - no. of test cases. The description of T test cases follows.
First line of each test case contains a single integer n - the number of farmers.
Next n lines contains four integers x1, y1, x2, y2 - the coordinates of bottom left and upper
right corner of plot of land.
 

Output:
For each test case, print a single line containing one integer - maximum area of the land which
gets completely irrigated.

 

Constraints:
1 \(\leq\) T \(\leq\)  10
1 \(\leq\)  n \(\leq\)  10, 000
-109  \(\leq\)  x1 < x2 \(\leq\)  109
-109 \(\leq\)  y1 < y2 \(\leq\)  109

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

In first test case area of region from (1, 1) to (4, 4) is 3 * 3 = 9, which is shared by at least 2 farmers.

In second test case there is no region which is shared by at least 3 farmers.

Editor Image

?