## IOI '16 P6 - Aliens (Standard I/O)

View as PDF

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type

Our satellite has just discovered an alien civilization on a remote planet. We have already obtained a low-resolution photo of a square area of the planet. The photo shows many signs of intelligent life. Our experts have identified points of interest in the photo. The points are numbered from to . We now want to take high-resolution photos that contain all of those points.

Internally, the satellite has divided the area of the low-resolution photo into an by grid of unit square cells. Both rows and columns of the grid are consecutively numbered from to (from the top and left, respectively). We use to denote the cell in row and column . The point number is located in the cell . Each cell may contain an arbitrary number of these points.

Our satellite is on a stable orbit that passes directly over the main diagonal of the grid. The main diagonal is the line segment that connects the top left and the bottom right corner of the grid. The satellite can take a high-resolution photo of any area that satisfies the following constraints:

• the shape of the area is a square,
• two opposite corners of the square both lie on the main diagonal of the grid,
• each cell of the grid is either completely inside or completely outside the photographed area.

The satellite is able to take at most high-resolution photos.

Once the satellite is done taking photos, it will transmit the high-resolution photo of each photographed cell to our home base (regardless of whether that cell contains some points of interest). The data for each photographed cell will only be transmitted once, even if the cell was photographed several times.

Thus, we have to choose at most square areas that will be photographed, assuring that:

• each cell containing at least one point of interest is photographed at least once, and
• the number of cells that are photographed at least once is minimized.

Your task is to find the smallest possible total number of photographed cells.

#### Input Specification

Line of input contains three space separated integers, , , and , the number of points of interest, the number of rows (and also columns) in the grid, and the maximum number of photos the satellite can take, respectively. Lines of input each contain two space separated integers, and . The th point of interest is located in the cell .

#### Output Specification

Your program should output the smallest possible total number of cells that are photographed at least once (given that the photos must cover all points of interest).

#### Sample Input 1

5 7 2
0 3
4 4
4 6
4 5
4 6

#### Sample Output 1

25

#### Explanation of Sample Output 1

In this example we have a grid with points of interest. The points of interest are located in four different cells: , , and . You may take at most high-resolution photos.

One way to capture all five points of interest is to make two photos: a photo of the square containing the cells and , and a photo of the square containing the cells and . If the satellite takes these two photos, it will transmit the data about cells. This amount is not optimal.

The optimal solution uses one photo to capture the square containing cells and and another photo to capture the square containing cells and . This results in only photographed cells, which is optimal, so take_photos should return .

Note that it is sufficient to photograph the cell once, even though it contains two points of interest.

This example is shown in the figures below. The leftmost figure shows the grid that corresponds to this example. The middle figure shows the suboptimal solution in which cells were photographed. The rightmost figure shows the optimal solution.

#### Sample Input 2

2 6 2
1 4
4 1

#### Sample Output 2

16

#### Explanation for Sample Output 2

Here we have points of interest located symmetrically: in the cells and . Any valid photo that contains one of them contains the other one as well. Therefore, it is sufficient to use a single photo.

The figures below show this example and its optimal solution. In this solution the satellite captures a single photo of cells.