This page is still under construction.

Parts of this page are still being built. What you see may change.

Largest Square

Time limit2sMemory limit128 MB

Summary
Given an N by N grid with W bad cells listed explicitly, find the largest axis-aligned square containing at most L bad cells.
Level

Medium7 of 10

Topics
Binary search, Prefix sum, Two pointers, Brute force
Solved
No attempts yet

Problem

There is an N×NN \times N mosaic of square solar cells (1≤N≤20001 \le N \le 2000). Each solar cell is either good or bad. There are WW bad cells (1≤W≤500001 \le W \le 50000). You must find the largest square within the mosaic that contains at most LL (0≤L≤W0 \le L \le W) bad cells.

Input

The first line of input contains a single integer ZZ (Z≤20Z \le 20), the number of test cases. The ZZ test cases then follow.

The first line of a test case contains three space-separated integers NN, WW, and LL. The next WW lines each contain two space-separated integers giving the row and column (each from 11 to NN) of a bad solar cell.

Output

For each input instance, output a single integer: the area of the largest square that contains no more than LL bad solar cells.

Hint

Suppose the mosaic is 4×44 \times 4 with the following arrangement of good ('G') and bad ('B') cells:

BGGG
GBBG
GGGG
GGGG

Several 2×22 \times 2 squares near the bottom contain no bad cells, but every 3×33 \times 3 square contains at least two bad cells.

Examples3

  1. Example 1

    Input
    1
    4 3 1
    1 1
    2 2
    2 3
    
    Expected output
    4
    
  2. Example 2

    Input
    1
    4 3 0
    1 1
    2 2
    2 3
    
    Expected output
    4
    
  3. Example 3

    Input
    1
    5 4 4
    1 1
    1 5
    5 1
    5 5
    
    Expected output
    25