This page is still under construction.

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

Diamonds

Time limit1sMemory limit128 MB

Summary
For each count Pmin, find the smallest radius whose worst-case center covers at least Pmin points, then the best coverage at that radius.
Level

Medium6 of 10

Topics
Geometry, Prefix sum, Implementation, Brute force
Solved
No attempts yet

Problem

Consider a planar grid with MM rows and NN columns. It has exactly MNMN intersections, each identified by a coordinate pair (i,j)(i, j) with i=0,1,…,N−1i = 0, 1, \ldots, N-1 (the column, or xx-coordinate) and j=0,1,…,M−1j = 0, 1, \ldots, M-1 (the row, or yy-coordinate).

Now place K≤MNK \le MN points on KK distinct intersections.

A diamond D(i,j,r)D(i, j, r) is centred at intersection (i,j)(i, j) and is a square of diagonal length 2r2r rotated 45∘45^\circ; its radius rr is any integer with r≥1r \ge 1. Equivalently, D(i,j,r)D(i, j, r) covers exactly the points whose Manhattan distance from the centre is at most rr, that is, every point (x,y)(x, y) with ∣x−i∣+∣y−j∣≤r|x - i| + |y - j| \le r.

For each Pmin⁡=1,2,…,KP_{\min} = 1, 2, \ldots, K, find the smallest radius Rmin⁡(Pmin⁡)R_{\min}(P_{\min}) such that a diamond of that radius is guaranteed to cover at least Pmin⁡P_{\min} points no matter which intersection its centre is placed on. In other words, Rmin⁡(Pmin⁡)R_{\min}(P_{\min}) is the smallest rr for which the worst case (the minimum, over all centres, of the number of covered points) is at least Pmin⁡P_{\min}.

Let Pmax⁡(Pmin⁡)P_{\max}(P_{\min}) be the largest number of points that any single diamond of radius Rmin⁡(Pmin⁡)R_{\min}(P_{\min}) can cover.

For example, take five points at (0,0)(0,0), (4,0)(4,0), (2,2)(2,2), (0,4)(0,4), and (4,4)(4,4) on a grid of 55 rows and 77 columns. The diamond D(2,4,1)D(2,4,1) covers no point, D(2,1,2)D(2,1,2) covers one point, and D(3,3,4)D(3,3,4) covers four points.

Input

Line 1 contains the number of rows MM and the number of columns NN.

The remaining lines list the KK points (K≤MNK \le MN). Each point is given as a pair of integers: its xx-coordinate followed by its yy-coordinate. Points may be spread across one or more lines, and all values on a line are separated by one or more whitespace characters (spaces or tabs).

You may assume 1≤M≤1001 \le M \le 100 and 1≤N≤1001 \le N \le 100. Any point lying outside the grid (that is, x<0x < 0, x>N−1x > N-1, y<0y < 0, or y>M−1y > M-1) is invalid and must be discarded.

Output

Print a header line containing the three column titles Pmin, Rmin(Pmin), and Pmax(Pmin), then one line for each qualifying value of Pmin⁡P_{\min}.

For a value of Pmin⁡P_{\min}, output the triple Pmin⁡P_{\min}, Rmin⁡(Pmin⁡)R_{\min}(P_{\min}), Pmax⁡(Pmin⁡)P_{\max}(P_{\min}) only if a diamond of radius Rmin⁡(Pmin⁡)R_{\min}(P_{\min}) is guaranteed to cover exactly Pmin⁡P_{\min} points. When two consecutive values share the same radius (for example Rmin⁡(2)=Rmin⁡(3)R_{\min}(2) = R_{\min}(3)), only the larger one qualifies, so the smaller value produces no line.

Each value is right-aligned so that its last character lines up with the last character of that column's heading, and columns are separated by two spaces.

Examples3

  1. Example 1

    Input
    5 	7
    0 	0 0 	4
    4 0
    4 4	       2 2
    	0 5
    
    Expected output
    Pmin  Rmin(Pmin)  Pmax(Pmin)
       1           4           5
       3           6           5
       4           8           5
       5          10           5
    
  2. Example 2

    Input
    1 1
    0 0
    
    Expected output
    Pmin  Rmin(Pmin)  Pmax(Pmin)
       1           1           1
    
  3. Example 3

    Input
    3 3
    1 1
    
    Expected output
    Pmin  Rmin(Pmin)  Pmax(Pmin)
       1           2           1