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 Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn argsort<T: std::cmp::Ord + std::marker::Copy>(v: &Vec<T>) -> Vec<usize> {
    let mut sort_v = Vec::new();
    for i in 0..v.len() {
        sort_v.push((v[i], i));
    }
    sort_v.sort();
    sort_v.iter().map(|x| x.1).collect::<Vec<usize>>()
}

fn argsort_map<T: std::cmp::Ord + std::marker::Copy>(v: &Vec<T>) -> Vec<usize> {
    let mut sort_v = Vec::new();
    for i in 0..v.len() {
        sort_v.push((v[i], i));
    }
    sort_v.sort();
    sort_v.iter().map(|x| x.1).collect::<Vec<usize>>()
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (n, k) = (v[0], v[1]);
    let mut x = vec![0; n];
    let mut y = vec![0; n];

    for i in 0..n {
        let v = read_vec::<i64>();
        x[i] = v[0];
        y[i] = v[1];
    }
    let sorted_y_indexes = argsort(&y);

    let mut ans = std::i64::MAX;
    for i in 0..n {
        for j in i + 1..n {
            let mut i = i;
            let mut j = j;
            if x[i] > x[j] {
                std::mem::swap(&mut i, &mut j);
            }
            let x1 = x[i];
            let x2 = x[j];
            assert!(x1 <= x2);

            let mut usable_point_indexes = Vec::new();
            for l in 0..n {
                let idx3 = sorted_y_indexes[l];
                if x[idx3] >= x1 && x[idx3] <= x2 {
                    usable_point_indexes.push(idx3);
                }
            }
            assert!(usable_point_indexes.len() >= 2);
            if usable_point_indexes.len() < k {
                continue;
            }

            for l in 0..usable_point_indexes.len() - k + 1 {
                let y1 = y[usable_point_indexes[l]];
                let y2 = y[usable_point_indexes[l + k - 1]];
                ans = min(ans, (x2 - x1) * (y2 - y1));
            }
        }
    }
    println!("{}", ans);
}