Splitting the Field
InterviewTime limit2sMemory limit512 MB
Compute how much fenced area is saved by covering all points with two disjoint axis-aligned rectangles instead of one.
- Level
Medium6 of 10
- Topics
- Sorting, Prefix sum, Geometry
- Solved
- No attempts yet
Problem
Farmer John keeps cows, and every cow stands at a different position in his two dimensional field. John wants one rectangular fence that encloses all of the cows. Its sides are parallel to the and axes, and among all rectangles that contain every cow it has the smallest area. A cow on the boundary counts as enclosed.
Milk production dropped last quarter, so the budget is tight. To cut the maintenance cost John wants to build two enclosures instead of one and fence a smaller total area. The two enclosures are also rectangles with sides parallel to the and axes, together they must contain every cow, and they may not overlap, not even on their boundaries. An enclosure of zero area is allowed, so an enclosure may have zero width or zero height.
Compute the area of the single enclosure minus the smallest possible total area of two enclosures.
Input
The first line contains the number of cows . ()
Each of the next lines contains the coordinates and of one cow, separated by a space. ()
All cow positions are different.
Output
Print one integer, the area John saves by building two enclosures instead of one.