8145: Load Balancing

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:12 通过:1

题目描述

农夫约翰的 N 头奶牛分别位于其二维农场的不同位置,(x1,y1)…(xN,yN),保证 xi,yi 均为正奇数,且不超过 B

约翰希望构建一个南北方向的无限长的栅栏来划分他的农场,栅栏可用 x=a 来表示,a 必须为偶数。

此外,他还希望构建一个东西方向的无限长的栅栏,该栅栏可用 y=b 来表示,b 必须为偶数。

这两个栅栏在点 (a,b) 处相交,将田地划分为了四个区域。

约翰希望通过合理的选择 a,b,使得四个区域的奶牛数量尽可能均衡,不会存在某个区域包含太多的奶牛。

M 表示四个区域中包含奶牛数量最多的区域所包含的奶牛数量。

约翰希望 M 尽可能小,请你计算,M 的最小可能值。

输入格式

第一行包含整数 N B

接下来 N 行,每行包含两个整数 x,y,表示其中一头奶牛的位置的横纵坐标。

输出格式

输出 M 的最小可能值。

数据范围

1≤N≤100,

1≤B≤106


Farmer John's N cows are each standing at distinct locations (x1,y1)…(xn,yn) on his two-dimensional farm (1≤N≤1001≤N≤100, and the xi's and yi's are positive odd integers of size at most B). FJ wants to partition his field by building a long (effectively infinite-length) north-south fence with equation x=a (a will be an even integer, thus ensuring that he does not build the fence through the position of any cow). He also wants to build a long (effectively infinite-length) east-west fence with equation y=b, where b is an even integer. These two fences cross at the point (a,b), and together they partition his field into four regions.

FJ wants to choose a and b so that the cows appearing in the four resulting regions are reasonably "balanced", with no region containing too many cows. Letting M be the maximum number of cows appearing in one of the four regions, FJ wants to make M as small as possible. Please help him determine this smallest possible value for M.

For the first five test cases, B is guaranteed to be at most 100. In all test cases, B is guaranteed to be at most 1,000,000.

INPUT FORMAT (file balancing.in):

The first line of the input contains two integers, N and B. The next n lines each contain the location of a single cow, specifying its x and y coordinates.

OUTPUT FORMAT (file balancing.out):

You should output the smallest possible value of M that FJ can achieve by positioning his fences optimally.

SAMPLE INPUT:

7 10
7 3
5 5
9 7
3 1
7 7
5 3
9 1

SAMPLE OUTPUT:

2

Problem credits: Brian Dean

输入样例 复制


输出样例 复制