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 Python (3.4.3) (judge verdict: Runtime Error)

import bisect
# x or y で sortしてK個見る
# これだけだと同一xに対して複数の選択がある時に落ちる
# 群数列てきな考えがいる？
n, k = map(int, input().split())

point = []
for i in range(n):
    point.append(list(map(int, input().split())))
point.sort()

# Xのポイント
dic = {}
for i in set([j[0] for j in point]):
    dic[i] = []
for i in point:
    dic[i[0]].append(i[1])
for i in set([j[0] for j in point]):
    dic[i].sort()

ans_prob = []
for i in range(n - k + 1):
    xmin = point[i][0]
    xmax = point[i + k - 1][0]
    #
    if xmin == xmax:
        print(0)
        exit()
    else:
        mid_flag = 0
        _y = []
        for j in range(i, i+k):
            if point[j][0] != xmin and point[j][0] != xmax:
                mid_flag = 1
                _y.append(point[j][1])

        #xminとxmaxの間に要素が存在しない時
        if mid_flag == 0:
            ret = 4*10**18
            for j in dic[xmin]:
                for k in dic[xmax]:
                    ret = min(ret, abs(j - k))
            ans_prob.append(ret)
        else:
            ymax_other = max(_y)
            ymin_other = min(_y)
            #これがどこに入るか考えなければいけない
            #xminについて
            flag = 0
            #xminが入らない時
            if dic[xmin][0] > ymax_other:
                ymax_other = dic[xmin][0]
            elif dic[xmin][-1] < ymin_other:
                ymin_other = dic[xmin][-1]
            else:
                xmin_point_min = bisect.bisect_left(dic[xmin], ymin_other)
                xmin_point_max = bisect.bisect_left(dic[xmin], ymax_other)
                #途中で入れないとき  xminが[1,5]のときに[2,3]のとき
                if xmin_point_max == xmin_point_min:
                    flag = 1
                    xmin_left = dic[xmin][xmin_point_max - 1]
                    xmin_right = dic[xmin][xmin_point_max]
                    hozon = ymin_other
                    ymin_other = xmin_left
                    #xmin_rightが採用される時を追加で判定すればいい
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            #xmaxについて
            #xmaxが入らない時
            if dic[xmax][0] > ymax_other:
                ymax_other = dic[xmax][0]
            elif dic[xmax][-1] < ymin_other:
                ymin_other = dic[xmax][-1]
            else:
                xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                if xmax_point_max == xmax_point_min:
                    xmax_left = dic[xmax][xmax_point_max]
                    xmax_right = dic[xmax][xmax_point_max + 1]
                    if ymin_other - xmax_left < xmax_right - ymax_other:
                        ymin_other = xmax_left
                    else:
                        ymax_other = xmax_right
                # 入る時つまりymin, ymaxに変化なし
                else:
                    pass
            ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

            if flag != 0:
                ymin_other = hozon
                ymax_other = xmin_right

                if dic[xmax][0] > ymax_other:
                    ymax_other = dic[xmax][0]
                elif dic[xmax][-1] < ymin_other:
                    ymin_other = dic[xmax][-1]
                else:
                    xmax_point_min = bisect.bisect_left(dic[xmax], ymin_other)
                    xmax_point_max = bisect.bisect_left(dic[xmax], ymax_other)
                    #途中で入れないとき  xmaxが[1,5]のときに[2,3]のとき
                    if xmax_point_max == xmax_point_min:
                        xmax_left = dic[xmax][xmax_point_max]
                        xmax_right = dic[xmax][xmax_point_max + 1]
                        if ymin_other - xmax_left < xmax_right - ymax_other:
                            ymin_other = xmax_left
                        else:
                            ymax_other = xmax_right
                    # 入る時つまりymin, ymaxに変化なし
                    else:
                        pass
                ans_prob.append((xmax - xmin)*(ymax_other - ymin_other))

ans_prob.sort()
print(ans_prob[0])