PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000485. Chụp ảnh nền văn minh ngoài hành tinh (Aliens)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 mm rows and mm columns, numbered from 00 through m−1m-1 from top to bottom and left to right. Cell (r,c)(r,c) is in row rr and column cc. Scientists have marked nn points for further observation, indexed from 00 through n−1n-1; point ii is in cell (ri,ci)(r_i,c_i). 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 (x,y)(x,y) with a≤x,y≤ba\le x,y\le b for integers 0≤a≤b<m0\le a\le b<m.

At most kk 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 n,m,kn,m,k: the number of marked points, grid size and maximum number of photographs.
  • Each of the next nn lines, line i+2i+2 for 0≤i<n0\le i<n, contains two integers ri,cir_i,c_i, the row and column of point ii.

Output

Print one integer: the minimum number of distinct photographed cells while covering every marked point.

Subtasks

  • Subtask 1 (4 points): 1≤n≤501\le n\le 50; 1≤m≤1001\le m\le 100; 1≤k≤n1\le k\le n; 0≤ri,ci<m0\le r_i,c_i<m for every 0≤i<n0\le i<n; k=nk=n.
  • Subtask 2 (12 points): 1≤n≤5001\le n\le 500; 1≤m≤10001\le m\le 1000; 1≤k≤n1\le k\le n; 0≤ri,ci<m0\le r_i,c_i<m for every 0≤i<n0\le i<n; ri=cir_i=c_i for every 0≤i<n0\le i<n.
  • Subtask 3 (9 points): 1≤n≤5001\le n\le 500; 1≤m≤10001\le m\le 1000; 1≤k≤n1\le k\le n; 0≤ri,ci<m0\le r_i,c_i<m for every 0≤i<n0\le i<n.
  • Subtask 4 (16 points): 1≤n≤40001\le n\le 4000; 1≤m≤10000001\le m\le 1000000; 1≤k≤n1\le k\le n; 0≤ri,ci<m0\le r_i,c_i<m for every 0≤i<n0\le i<n.
  • Subtask 5 (19 points): 1≤n≤500001\le n\le 50000; 1≤m≤10000001\le m\le 1000000; 1≤k≤n1\le k\le n; 0≤ri,ci<m0\le r_i,c_i<m for every 0≤i<n0\le i<n; k≤100k\le100.
  • Subtask 6 (40 points): 1≤n≤1000001\le n\le 100000; 1≤m≤10000001\le m\le 1000000; 1≤k≤n1\le k\le n; 0≤ri,ci<m0\le r_i,c_i<m for every 0≤i<n0\le i<n.

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: (0,3),(4,4),(4,5),(4,6)(0,3),(4,4),(4,5),(4,6), with two points in the last cell. One feasible but nonoptimal choice uses the squares spanning indices 00 to 55 and 44 to 66. Their union has 36+9−4=4136+9-4=41 cells because the overlap is 2×22\times2.

Instead, use the squares spanning 00 to 33 and 44 to 66. They are disjoint and cover 42+32=254^2+3^2=25 cells. Any photo of (0,3)(0,3) must contain the first 16 cells, and any photo of (4,6)(4,6) 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.

Example 1

Input 2

2 6 2
1 4
4 1

Output 2

16

Explanation 2

The cells (1,4)(1,4) and (4,1)(4,1) are symmetric about the main diagonal. A photo containing either cell must include the square spanning indices 11 to 44, which also contains the other cell. It has 42=164^2=16 cells, all necessary; one photo suffices.

Example 2