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
pathfinder1729: 2021-07-23 23:55:28

cover for n=0!!!!!!

charchit099: 2021-07-22 02:56:17


mojo__jojo: 2021-07-10 08:06:09

I like cock.

Last edit: 2021-07-25 23:07:19
shr_3: 2021-06-30 07:49:57

complexity would be O(2*Nlog(N)) whare N -> n+2

kshitij_56: 2021-05-25 11:24:34

What is the complexity of this

prateekpamecha: 2021-05-13 10:47:42

Here is my penis:


Last edit: 2021-05-13 12:41:53
nspatilme: 2021-04-02 08:05:21

Used BufferedReader for taking input though getting TLE in JAVA

Last edit: 2021-04-02 11:36:52
backtobas: 2020-11-11 16:21:00

I am getting runtime error!

akashmodak97: 2020-08-29 10:29:37

Be sure that you're checking about n=0, that cost me one WA :)

pranay2516: 2020-05-11 18:43:26

Finally AC! Dont forget to add the edges

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