Problem:
Score : 400 points

Problem Statement

We have N points in a two-dimensional plane.

The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i).

Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior.

Here, points on the sides of the rectangle are considered to be in the interior.

Find the minimum possible area of such a rectangle.

Constraints

2 \leq K \leq N \leq 50

-10^9 \leq x_i,y_i \leq 10^9 (1 \leq i \leq N)

x_i≠x_j (1 \leq i<j \leq N)

y_i≠y_j (1 \leq i<j \leq N)

All input values are integers. (Added at 21:50 JST)

Input

Input is given from Standard Input in the following format:

N K
x_1 y_1
:
x_{N} y_{N}

Output

Print the minimum possible area of a rectangle that satisfies the condition.

Sample Input 1

4 4
1 4
3 3
6 2
8 1

Sample Output 1

21

One rectangle that satisfies the condition with the minimum possible area has the following vertices: (1,1), (8,1), (1,4) and (8,4).

Its area is (8-1) × (4-1) = 21.

Sample Input 2

4 2
0 0
1 1
2 2
3 3

Sample Output 2

1

Sample Input 3

4 3
-1000000000 -1000000000
1000000000 1000000000
-999999999 999999999
999999999 -999999999

Sample Output 3

3999999996000000001

Watch out for integer overflows.

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.*;

public class Main {
	public static void main(String[] args) {
		D();
		return;
	}
	
	public static void A() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		if(A==B) System.out.println(C);
		else if(B==C) System.out.println(A);
		else System.out.println(B);
	}

	// #を読めば、その周囲に数字を入れる
	// -1は#に対応する 空間O(n)
	//あるいは、ますの８方向を確認する　時間O(n)　空間O(1）
	
	public static void calc8(char[][] cell ,int h, int w) {
		if(cell[h][w] == '#') System.out.print('#');
		else {
			int[] hs = new int[] {h-1,h,h+1};
			int[] ws = new int[] {w-1,w,w+1};
			int sum = 0;
			for(int nh: hs) {
				for(int nw : ws) {
					if(nh<cell.length && nh>=0 && nw >=0 && nw < cell[0].length) {
						if(cell[nh][nw]=='#') sum++;
					}
				}
			}
			System.out.print(sum);
		}
		if(w == cell[0].length-1) System.out.println("");
	}
	
	public static void B() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] cell = new char[H][W];
		for(int i=0;i<H;i++) {
			String s = sc.next();
			for(int j=0; j<W;j++) {
				cell[i][j] = s.charAt(j);
			}
		}
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				calc8(cell,i,j);
			}
		}
	}
	
	
	//グラフが大きいならば、双方向探索も有効
	//最初は連結と仮定した場合
	// 隣接行列matに置いて、iとjが連結か調べる　WFS
	public static boolean connect(int[][] mat, int i, int j) {
		boolean[] visit = new boolean[mat.length];
		LinkedList<Integer> que = new LinkedList<Integer>();
		que.add(i);
		while(!que.isEmpty()) {
			int check = que.removeFirst();
			if(check == j) return true;
			//System.out.println(check + " check");
			visit[check] = true;
			for(int w=0;w<mat.length;w++) {
				if (mat[check][w] == 1 && (!visit[w])) {
					//System.out.println(mat[check][w] + "e");
					que.add(w);
					visit[w] = true;
				}
			}
		}
		return false;
	}
	public static void C() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] mat = new int[N][N];
		int[][] edge = new int[M][2];
		for(int i=0;i<M;i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			mat[a][b] = mat[b][a] = 1;
			edge[i] = new int[] {a,b};
		}
		int count = 0;
		for(int i=0;i<M;i++) {
			int a = edge[i][0];
			int b = edge[i][1];
			mat[a][b] = mat[b][a] = 0;
			if(!connect(mat,a,b)) count++;
			mat[a][b] = mat[b][a] = 1;
		}
		System.out.println(count);
	}

	// N^4の長方形
	//点が含まれるかを確認
	public static int containdpoint(int[][] lis, int xl, int xr, int yd, int yu) {
		int count = 0;
		for(int i=0;i<lis.length;i++) {
			int x = lis[i][0];
			int y = lis[i][1];
			//System.out.println(x + " " + y + " " + xl + " " + xr);
			if(xl <= x && x<=xr && yd<=y && y<=yu) count++;
		}
		//System.out.println(count);
		return count;
	}
	
	public static void D() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] xs = new int[N];
		int[] ys = new int[N];
		int[][] lis = new int[N][2];
		for(int i=0;i<N;i++) {
			xs[i] = lis[i][0] = sc.nextInt();
			ys[i] = lis[i][1] = sc.nextInt();
		}
		Arrays.sort(xs);
		Arrays.sort(ys);
		long min = Long.MAX_VALUE;
		for(int xlidx = 0; xlidx<N-1; xlidx++) {
			for(int xridx = xlidx+1;xridx<N;xridx++) {
				for(int ydidx = 0; ydidx<N-1; ydidx++) {
					for(int yuidx = ydidx+1; yuidx < N; yuidx++) {
						if (containdpoint(lis, xs[xlidx],xs[xridx],ys[ydidx],ys[yuidx])>=K) {
							min = Math.min(min, (xs[xridx]-xs[xlidx])*(long)(ys[yuidx]-ys[ydidx]));
						}
					}
				}
			}
		}
		System.out.println(min);
	}
}