DEFKIN - Defense of a Kingdom

no tags 

Theodore implements a new strategy game “Defense of a Kingdom”. On each level a player defends the Kingdom that is represented by a rectangular grid of cells. The player builds crossbow towers in some cells of the grid. The tower defends all the cells in the same row and the same column. No two towers share a row or a column.

The penalty of the position is the number of cells in the largest undefended rectangle. For example, the position shown on the picture has penalty 12.

This position has a penalty of 12.

Help Theodore write a program that calculates the penalty of the given position.


The first line of the input file contains the number of test cases.

Each test case consists of a line with three integer numbers: w — width of the grid, h — height of the grid and n — number of crossbow towers (1 ≤ w, h ≤ 40 000; 0 ≤ n ≤ min(w, h)).

Each of the following n lines contains two integer numbers xi and yi — the coordinates of the cell occupied by a tower (1 ≤ xi ≤ w; 1 ≤ yi ≤ h).


For each test case, output a single integer number — the number of cells in the largest rectangle that is not defended by the towers.


15 8 3
3 8
11 2
8 6


hide comments
Sahil Dua: 2014-11-04 09:19:30

Easier than what it looks like initially. O(nlogn) accepted :)

renters_Land: 2014-06-27 07:03:12

good 1 :)
the constraints make the ques even better.
int is enough..

****: 2014-01-23 18:50:02


Last edit: 2014-01-23 18:55:49
Venkatesh Ganesan: 2013-12-26 14:29:41

No need of long long. Constraints are right. I used only int and got AC.

P_Quantum: 2013-12-23 19:12:14

int--> WA
long long--> AC

J_P: 2013-12-19 11:38:37

wrong data type costed me 6 WA... :(.. finally AC..:)

Secret: 2012-12-22 13:48:35

logical problem!!

Last edit: 2012-12-22 13:48:50
saket diwakar: 2012-11-29 22:38:58

cool one..:)

Bharath Reddy: 2012-07-10 05:59:23

Can anyone tell me some corner cases?
Getting WA..

Shashank Shekhar Mishra: 2012-07-05 19:57:34

what could be possibly wrong in my code?? its giving wa !! subm id-7266003

Last edit: 2012-07-05 20:05:32

Added by:Fidel Schaposnik
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ACM ICPC 2010, NEERC, Northern Subregional Contest