Smallest Square 2

Time limit2sMemory limit512 MB

Summary
Given N lattice points, choose an axis-aligned square with lattice corners containing at least K points strictly inside and minimize its area.
Level

Medium7 of 10

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

Problem

There are NN points on the coordinate plane. Every point has integer coordinates.

Consider the squares that satisfy all three conditions below.

  • All four corners have integer coordinates.
  • Every side is parallel to a coordinate axis.
  • At least KK points lie strictly inside the square. A point on the boundary does not count as being inside.

Write a program that finds the smallest area among these squares.

Input

The first line contains the number of points NN and an integer KK. (2≤N≤1002 \le N \le 100, 1≤K≤N1 \le K \le N)

Each of the next NN lines contains the coordinates xx and yy of one point, separated by a space. (−109≤x,y≤109-10^9 \le x, y \le 10^9)

No point is given more than once.

Output

Print the smallest area among the squares that satisfy the conditions.

Examples3

  1. Example 1

    Input
    2 2
    0 0
    3 7
    
    Expected output
    81
    
  2. Example 2

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

    Input
    6 4
    0 0
    0 1
    1 0
    1 1
    2 0
    2 1
    
    Expected output
    9