Balanced Fence Partition
InterviewTime limit2sMemory limit512 MB
Place one vertical and one horizontal fence between grid points to minimize the largest cow count in the four regions.
- Level
Easy3 of 10
- Topics
- Brute force, Sorting
- Solved
- No attempts yet
Problem
Farmer John's cows each stand at a distinct location on his two-dimensional farm. Every coordinate and is a positive odd integer no larger than .
John wants to split the farm with a north-south fence of effectively infinite length, given by the equation . The value is even, so the fence never runs through the spot where a cow stands. He also builds an east-west fence of effectively infinite length given by , where is even as well. The two fences cross at the point and cut the farm into four regions.
John wants the cows spread evenly over the four regions, with no single region holding too many of them. Let be the number of cows in the most crowded of the four regions. Find the smallest value of he can reach.
Input
The first line contains two integers and (, ), separated by a space. Each of the next lines contains the coordinate and the coordinate of one cow. Every coordinate is a positive odd integer no larger than , and no two cows share a location.
Output
Print on one line the smallest value of that John can reach by placing the two fences optimally.