/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
海を真上から見た二次元平面上に N 匹の魚がいます。i 番目の魚は座標 (X_i, Y_i) にいます。同じ座標に複数の魚が存在することもあります。
高橋君は、x 軸方向の長さが W、y 軸方向の長さが H の長方形の網を 1 回だけ使って、できるだけ多くの魚を捕まえたいと考えています。
網の各辺は x 軸または y 軸に平行になるように置く必要があり、回転させることはできません。網は平面上の任意の実数座標の位置に置くことができます。具体的には、ある実数 a, b を選び、左下の頂点が (a, b) となるように網を置くと、長方形領域 a \leq x \leq a + W かつ b \leq y \leq b + H の内部または辺上にいる魚をすべて捕まえることができます。
高橋君が捕まえることのできる魚の数の最大値を求めてください。
制約
- 1 \leq N \leq 3000
- 1 \leq W \leq 10^9
- 1 \leq H \leq 10^9
- -10^9 \leq X_i \leq 10^9
- -10^9 \leq Y_i \leq 10^9
- 入力はすべて整数である
入力
N W H X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
1 行目には、魚の数 N、網の x 軸方向の長さ W、網の y 軸方向の長さ H がスペース区切りで与えられる。続く N 行のうち i 行目には、i 番目の魚の座標 X_i, Y_i がスペース区切りで与えられる。
出力
高橋君が捕まえることのできる魚の数の最大値を 1 行で出力せよ。
入力例 1
5 2 2 0 0 1 1 2 2 3 0 0 3
出力例 1
3
入力例 2
6 1 1 0 0 0 0 1 1 1 0 2 1 -1 -1
出力例 2
4
入力例 3
12 4 3 -3 0 -2 1 -1 2 0 0 1 1 2 2 3 3 4 1 5 0 6 2 1 4 2 -1
出力例 3
6
入力例 4
20 5 4 -5 -5 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5 5 1 6 2 7 3 8 4 9 5 2 0 2 0 3 1 3 1 10 10
出力例 4
9
入力例 5
1 1 1 1000000000 -1000000000
出力例 5
1
Score : 400 pts
Problem Statement
On a two-dimensional plane viewing the sea from directly above, there are N fish. The i-th fish is located at coordinates (X_i, Y_i). Multiple fish may exist at the same coordinates.
Takahashi wants to catch as many fish as possible using a rectangular net of length W in the x-axis direction and length H in the y-axis direction, which he can use exactly once.
Each side of the net must be placed parallel to the x-axis or y-axis, and it cannot be rotated. The net can be placed at any position with real-valued coordinates on the plane. Specifically, by choosing real numbers a, b and placing the net so that its bottom-left corner is at (a, b), he can catch all fish that are inside or on the boundary of the rectangular region a \leq x \leq a + W and b \leq y \leq b + H.
Find the maximum number of fish that Takahashi can catch.
Constraints
- 1 \leq N \leq 3000
- 1 \leq W \leq 10^9
- 1 \leq H \leq 10^9
- -10^9 \leq X_i \leq 10^9
- -10^9 \leq Y_i \leq 10^9
- All input values are integers
Input
N W H X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
The first line contains the number of fish N, the length of the net in the x-axis direction W, and the length of the net in the y-axis direction H, separated by spaces. Each of the following N lines contains the coordinates X_i, Y_i of the i-th fish, separated by spaces.
Output
Print the maximum number of fish that Takahashi can catch, on a single line.
Sample Input 1
5 2 2 0 0 1 1 2 2 3 0 0 3
Sample Output 1
3
Sample Input 2
6 1 1 0 0 0 0 1 1 1 0 2 1 -1 -1
Sample Output 2
4
Sample Input 3
12 4 3 -3 0 -2 1 -1 2 0 0 1 1 2 2 3 3 4 1 5 0 6 2 1 4 2 -1
Sample Output 3
6
Sample Input 4
20 5 4 -5 -5 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5 5 1 6 2 7 3 8 4 9 5 2 0 2 0 3 1 3 1 10 10
Sample Output 4
9
Sample Input 5
1 1 1 1000000000 -1000000000
Sample Output 5
1