#P8370. [POI 2001 R3] Goldmine

[POI 2001 R3] Goldmine

Problem Description

As one of the most meritorious employees of The Goldmine\text{The Goldmine} in Byteland\text{Byteland}, Byteman\text{Byteman} is going to retire at the end of the year.

To recognize his diligent work, the management of The Goldmine\text{The Goldmine} is willing to reward him with a small rectangular mining plot. The side lengths of this plot are ss and ww, and its sides are parallel to the axes of the coordinate system. He can choose the position of the rectangle himself. Of course, the value of the plot depends on its position. Its value is defined as the number of natural gold ores within this area (if an ore lies on the boundary of the plot, it is also considered to be inside the area).

Your task is to compute the maximum possible value of such a plot (i.e., choose the best position for it). For simplicity, assume that the entire mining area is infinite, but the region containing natural gold ores is finite.

Write a program that:

  1. Reads the positions of the natural gold ores.

  2. Computes the maximum possible value of this plot (i.e., the maximum number of natural gold ores contained in a rectangle of the given size).

Input Format

The first line contains two positive integers s,ws, w, representing the lengths of the sides of the rectangle parallel to the XX axis and the YY axis, respectively.

The second line contains a positive integer nn, which denotes the number of natural ores in this goldmine area. The next nn lines each contain two integers x,yx, y separated by a single space, representing the XX coordinate and the YY coordinate of a natural gold ore.

Output Format

Output one integer, representing the maximum value of a mining plot of the given size.

1 2
12
0 0
1 1
2 2
3 3
4 5
5 5
4 2
1 4
0 5
5 0
2 3
3 2
4

Hint

For 100%100\% of the data: $1 \le s, w \le 10000, 1 \le n \le 15000, -30000 \le x, y \le 30000$.

Translated by ChatGPT 5