Load Balancing
Time limit2sMemory limit512 MB
Place one vertical and one horizontal fence between the odd-coordinate cow positions to minimize the largest cow count in any of the four regions.
- Level
Medium5 of 10
- Topics
- Sorting, Prefix sum, Brute force
- Solved
- No attempts yet
Problem
Farmer John's cows stand at distinct points on his two-dimensional farm (, and every and is a positive odd integer of size at most ). FJ wants to divide the field by building a north-south fence with equation . The fence is effectively infinite in length, and is an even integer, so the fence never passes through the position of a cow. He also builds an east-west fence with equation , where is an even integer as well. The two fences cross at the point and together cut the field into four regions.
FJ wants to choose and so that the cows in the four regions are reasonably balanced, with no region holding too many cows. Let be the largest number of cows in one of the four regions. FJ wants to make as small as possible. Determine that smallest possible value of .
Input
The first line contains a single integer . Each of the next lines contains the and coordinates of one cow, separated by a space.
Output
Print the smallest value of that FJ can achieve by placing the two fences optimally.