struct Combination {
    modp: usize,
    mfact: Vec<usize>,
    rfact: Vec<usize>,
}

impl Combination {
    fn new(size: usize, modp: usize) -> Self {
        let mut rfact = vec![0; size + 1];
        let mut mfact = vec![0; size + 1];
        mfact[0] = 1;
        for i in 1..mfact.len() {
            mfact[i] = (mfact[i - 1] * i) % modp;
        }
        rfact[size] = Self::inv(mfact[size], modp);
        for i in (0..size).rev() {
            rfact[i] = rfact[i + 1] * (i + 1) % modp;
        }

        Combination {
            modp: modp,
            mfact: mfact,
            rfact: rfact,
        }
    }

    fn pow(mut x: usize, mut n: usize, modp: usize) -> usize {
        let mut ret = 1;
        while n > 0 {
            if n & 1 > 0 {
                ret *= x;
                ret %= modp;
            }
            x *= x;
            x %= modp;
            n >>= 1;
        }
        ret
    }

    fn inv(x: usize, modp: usize) -> usize {
        Self::pow(x, modp - 2, modp)
    }

    fn C(&self, p: usize, q: usize) -> usize {
        if p < q {
            return 0;
        }
        (((self.mfact[p] * self.rfact[q]) % self.modp) * self.rfact[p - q]) % self.modp
    }
}

fn create_combination(size: usize, modp: usize) -> Vec<Vec<usize>> {
    let mut comb = vec![vec![0; size + 10]; size + 10];
    for i in 0..size + 1 {
        for j in 0..i + 1 {
            if j == 0 || j == i {
                comb[i][j] = 1;
            } else {
                comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % modp;
            }
        }
    }
    comb
}

fn create_combination_p(size: usize) -> Vec<Vec<f64>> {
    let mut comb = vec![vec![0.0; size + 10]; size + 10];
    comb[0][0] = 1.0;
    for i in 1..size + 1 {
        for j in 0..i + 1 {
            comb[i][j] += comb[i - 1][j] / 2.0;
            if j > 0 {
                comb[i][j] += comb[i - 1][j - 1] / 2.0;
            }
        }
    }
    comb
}

#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn main() {
    input! {
        n: usize,
        k: usize,
        mut a: [i64; n],
    }

    let comb = Combination::new(100001, M as usize);
    a.sort();

    let mut max_sum = 0i64;
    for i in k - 1..n {
        let mut s = a[i] * comb.C(i, k - 1) as i64;
        s %= M;
        // println!("{} {}", a[i], s);
        max_sum += s;
        max_sum %= M;
    }

    let mut min_sum = 0;
    for i in 0..n - k + 1 {
        let mut s = a[i] * comb.C(n - i - 1, k - 1) as i64;
        s %= M;
        // println!("{} {}", a[i], s);
        min_sum += s;
        min_sum %= M;
    }

    // println!("{} {}", max_sum, min_sum);

    println!("{}", (M + max_sum - min_sum) % M);
}


Measured memory_bytes: 6524