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 C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

// ref. http://codingmelon.com/2015/12/17/range-sum-query-2d-mutable-leetcode-308/
class FenwickTree2D
{
    private int[,] _tree, _ma;

    public FenwickTree2D(int h, int w)
    {
        _tree = new int[h + 1, w + 1];
        _ma = new int[h + 1, w + 1];
    }

    public void Update(int row, int col, int val)
    {
        var delta = val - _ma[row, col];
        _ma[row, col] = val;
        for (var i = row + 1; i <= _ma.GetLength(0); i += i & (-i))
            for (var j = col + 1; j <= _ma.GetLength(1); j += j & (-j)) _tree[i, j] += delta;
    }

    public int SumRegion(int row1, int col1, int row2, int col2)
        => Sum(row2, col2) + Sum(row1 - 1, col1 - 1) - Sum(row2, col1 - 1) - Sum(row1 - 1, col2);

    private int Sum(int row, int col)
    {
        var sol = 0;
        for (var i = row + 1; i > 0; i -= i & (-i))
            for (var j = col + 1; j > 0; j -= j & (-j)) sol += _tree[i, j];
        return sol;
    }
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;
        var k = io.I;
        var x = new long[n];
        var y = new long[n];

        for (var i = 0; i < n; i++)
        {
            x[i] = io.L;
            y[i] = io.L;
        }

        var px = x.OrderBy(t => t).ToArray();
        var py = y.OrderBy(t => t).ToArray();

        var rpx = new Dictionary<long, int>(n);
        var rpy = new Dictionary<long, int>(n);

        for (var i = 0; i < n; i++)
        {
            rpx[px[i]] = i;
            rpy[py[i]] = i;
        }

        var ft = new FenwickTree2D(n, n);

        for (var i = 0; i < n; i++)
            ft.Update(rpx[x[i]], rpy[y[i]], 1);

        var ans = long.MaxValue;

        for (var i = 0; i < n - 1; i++)
            for (var j = i + 1; j < n; j++)
                for (var l = 0; l < n - 1; l++)
                    for (var m = l + 1; m < n; m++)
                        if (ft.SumRegion(i, l, j, m) >= k)
                            ans = Min(ans, (px[j] - px[i]) * (py[m] - py[l]));

        io.Write(ans);
    }
}