Submit | All submissions | Best solutions | Back to list |
DEFKIN - Defense of a Kingdom |
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.
Help Theodore write a program that calculates the penalty of the given position.
Input
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).
Output
For each test case, output a single integer number — the number of cells in the largest rectangle that is not defended by the towers.
Example
Input: 1 15 8 3 3 8 11 2 8 6 Output: 12
Added by: | Fidel Schaposnik |
Date: | 2010-11-08 |
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 |
hide comments
|
|||||||
2020-05-11 18:43:26
Finally AC! Dont forget to add the edges |
|||||||
2019-10-13 10:48:23
just apply the greedy approach! |
|||||||
2019-08-04 13:33:32
handle n=0 case. cost me 2 WA |
|||||||
2018-03-10 01:10:02
Long Long - WA int -AC why? |
|||||||
2017-08-26 00:12:38
Wasted an hour trying to think of a better solution than the one I designed as a test, then gave up and submitted for the hell of it; got the best time in Python. Listen to minhthai's advice =) |
|||||||
2016-09-07 12:48:51 hacker
logical |
|||||||
2016-08-23 19:30:13 GAURAV CHANDEL
1st implemented O(n*logn*logn) sol..(not worked for me) 2nd implemented O(n*logn) sol..........(not worked for me) 3rd implemented O(max(w,h)) sol.. (This was the easiest and it worked)... Good Logical Problem... |
|||||||
2016-03-08 23:24:02
can be done in O(max(h,w)) |
|||||||
2016-02-01 21:10:14
width+1 and height+1 |
|||||||
2016-01-30 11:38:59 minhthai
be a simple coder :) Last edit: 2016-01-30 11:39:17 |