#P5920. [IOI 2005] gar
[IOI 2005] gar
Description
He planted roses in his garden.
Summer has come, and all the flowers are blooming beautifully. Byteman realized that he cannot take care of all the flowers in his garden by himself, so he decided to hire two gardeners to help him.
He wants to choose two rectangular areas in the garden and assign each one to a gardener. These two rectangles must not intersect or overlap, and each area must contain exactly roses.
Byteman wants to build fences around these two rectangular areas, but he does not have much money right now, so he wants to spend as little as possible. Your task is to help Byteman choose two rectangular areas such that, while satisfying the conditions, the sum of their perimeters is minimized.
Byteman's garden is meters long and meters wide. The garden is divided into identical grid cells. We set up a coordinate system parallel to the two sides of the garden. All grid cells have coordinates satisfying . Each cell may contain any number of roses.
The selected rectangles must have sides parallel to the sides of the garden, and the coordinates of the four corners of each rectangle must be integers. For and , a rectangle has four corners , , and :
-
The points contained in this rectangle satisfy and .
-
The perimeter of this rectangle is . The two selected rectangles must not overlap or intersect, meaning they cannot share any grid cell. Even if they share a boundary, their perimeters are still counted separately.
Input Format
The first line contains and .
The second line contains and .
The next lines contain the coordinates of the roses.
Output Format
Output only one line: the minimum total perimeter.
If there is no rectangle arrangement that satisfies the requirements, output NO.
6 5
7 3
3 4
3 3
6 1
1 1
5 5
5 5
3 1
22
Hint
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号