Under construction

Still being built. Things may change

Organization

Time limit2sMemory limit512 MB

Summary
Partition N points into k nonempty teams so that the minimum Manhattan distance between points in different teams is as large as possible.
Level

Medium7 of 10

Topics
Binary search, Sorting, Geometry
Solved
No attempts yet

Problem

A company has NN employees and splits them into kk nonempty teams. The company turns everything into numbers.

  • Employee aa took two tests and got two values xax_a and yay_a.
  • The difference between employees aa and bb is D(a,b)=∣xa−xb∣+∣ya−yb∣D(a, b) = |x_a - x_b| + |y_a - y_b|.
  • The strength index SISI of the company is the smallest D(a,b)D(a, b) over all pairs of employees aa, bb that sit in different teams.

Next year the company keeps kk teams and rearranges the employees so that the strength index is as large as possible. Compute the largest strength index that kk nonempty teams can reach.

Input

The first line contains the number of test cases TT. (1≤T≤101 \le T \le 10)

The first line of each test case contains the number of employees NN and the number of teams kk, separated by a single space. (2≤k≤102 \le k \le 10, k≤N≤1000k \le N \le 1000)

Each of the next NN lines contains the two test results xx and yy of one employee, separated by a single space. (0≤x,y≤100 0000 \le x, y \le 100\,000)

Output

For each test case, print the largest strength index on its own line.

Hint

Take the three employees (0,0)(0, 0), (2,2)(2, 2), (3,2)(3, 2) with k=2k = 2. Neither team may be empty, so there are three ways to split them. {(0,0)}\{(0,0)\} with {(2,2),(3,2)}\{(2,2), (3,2)\} gives SI=min⁡{4,5}=4SI = \min\{4, 5\} = 4, {(0,0),(2,2)}\{(0,0), (2,2)\} with {(3,2)}\{(3,2)\} gives SI=min⁡{5,1}=1SI = \min\{5, 1\} = 1, and {(0,0),(3,2)}\{(0,0), (3,2)\} with {(2,2)}\{(2,2)\} gives SI=min⁡{5,1}=1SI = \min\{5, 1\} = 1. The largest value is 44.

Take the six employees (0,1)(0,1), (0,0)(0,0), (1,0)(1,0), (2,2)(2,2), (2,3)(2,3), (3,2)(3,2) with k=2k = 2. There are 31 ways to split them, and {(0,1),(0,0),(1,0)}\{(0,1), (0,0), (1,0)\} with {(2,2),(2,3),(3,2)}\{(2,2), (2,3), (3,2)\} reaches the largest value SI=3SI = 3. That value comes from D((0,1),(2,2))D((0,1), (2,2)) and from D((1,0),(2,2))D((1,0), (2,2)).

Examples2

  1. Example 1

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

    Input
    1
    2 2
    0 0
    100000 100000
    
    Expected output
    200000