#BS0000485. Chụp ảnh nền văn minh ngoài hành tinh (Aliens)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chụp ảnh nền văn minh ngoài hành tinh (Aliens)
Aliens
Source: IOI
Version: Phuoc Hung OJ Extended
Problem Statement
A satellite has found evidence of extraterrestrial life in a surveyed square region. Represent the region by a grid of rows and columns, numbered from through from top to bottom and left to right. Cell is in row and column . Scientists have marked points for further observation, indexed from through ; point is in cell . Several points may occupy the same cell.
The satellite travels above the main diagonal, joining the upper-left and lower-right corners of the grid. Each detailed photograph must cover a square whose opposite corners lie on that diagonal. Its boundary follows grid lines, so no cell is cut. Equivalently, one photograph covers precisely the cells with for integers .
At most photographs may be taken. Every cell containing a marked point must occur in at least one photograph. Each photographed cell is transmitted to the base only once, even if multiple photographs contain it. Photographed cells without marked points count as well.
Determine the minimum number of distinct cells that must be transmitted.
Input
- The first line contains three integers : the number of marked points, grid size and maximum number of photographs.
- Each of the next lines, line for , contains two integers , the row and column of point .
Output
Print one integer: the minimum number of distinct photographed cells while covering every marked point.
Subtasks
- Subtask 1 (4 points): ; ; ; for every ; .
- Subtask 2 (12 points): ; ; ; for every ; for every .
- Subtask 3 (9 points): ; ; ; for every .
- Subtask 4 (16 points): ; ; ; for every .
- Subtask 5 (19 points): ; ; ; for every ; .
- Subtask 6 (40 points): ; ; ; for every .
Examples
Input 1
5 7 2
0 3
4 4
4 6
4 5
4 6
Output 1
25
Explanation 1
There are five marked points in four cells: , with two points in the last cell. One feasible but nonoptimal choice uses the squares spanning indices to and to . Their union has cells because the overlap is .
Instead, use the squares spanning to and to . They are disjoint and cover cells. Any photo of must contain the first 16 cells, and any photo of must contain the 9 cells of the second square. Those required sets are disjoint, proving the lower bound of 25. The diagrams show the points, the 41-cell choice and the 25-cell choice.

Input 2
2 6 2
1 4
4 1
Output 2
16
Explanation 2
The cells and are symmetric about the main diagonal. A photo containing either cell must include the square spanning indices to , which also contains the other cell. It has cells, all necessary; one photo suffices.
