import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, K = lr()

A = lr()

A.sort()



MOD = 10 ** 9 + 7

if K == 1:

    print((0))

    exit()



def cmb(n, k):

    # nCkを計算する

    k = min(k, n-k)

    return fac[n] * ifac[k] % MOD * ifac[n-k] % MOD



def make_tables(MOD, n):

    # 階乗テーブル、逆元の階乗テーブルを作成する

    fac = [1, 1] # 階乗テーブル

    ifac = [1, 1] # 逆元の階乗テーブル

    inverse = [0, 1] # 逆元テーブル 0の階乗は1 0の逆元は0



    for i in range(2, n+1):

        fac.append((fac[-1] * i) % MOD)

        inverse.append((-inverse[MOD % i] * (MOD//i)) % MOD)

        ifac.append((ifac[-1] * inverse[-1]) % MOD)

    return fac, ifac



fac, ifac = make_tables(MOD, 10**6)

answer = 0

for i in range(K-1, N):

    # 最大値として何回登場するか、A[i] * i C (K-1)

    answer += A[i] * cmb(i, K-1)

    answer %= MOD



for i in range(N-K+1):

    # A[i] * (N-(i+1)) C (k-1)

    answer -= A[i] * cmb(N-(i+1), K-1)

    answer %= MOD



print((answer % MOD))

# 51
import sys

import numpy as np



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



MOD = 10 ** 9 + 7



# 組合せ nCr (MOD) 逆元を使う方法

def perm(n,k):

    if k > n or k < 0: return 0

    return fact[n] * fact_inv[n-k] % MOD



def cmb(n, k):

    if k < 0 or k > n: return 0 

    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD



def cumprod(arr, MOD):

    L = len(arr); Lsq = int(L**.5+1)

    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)

    for n in range(1, Lsq):

        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD

    for n in range(1, Lsq):

        arr[n] *= arr[n-1, -1]; arr[n] %= MOD

    return arr.ravel()[:L]



def make_fact(U, MOD):

    x = np.arange(U, dtype=np.int64); x[0] = 1

    fact = cumprod(x, MOD)

    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)

    fact_inv = cumprod(x, MOD)[::-1]

    return fact, fact_inv



U = 10 ** 5 + 100 # 階乗テーブルの上限

fact, fact_inv = make_fact(U, MOD)

N, K = lr()

A = np.array(lr())

A.sort()

if K == 1:

    print((0)); exit()

coef = np.zeros(N, np.int64)

coef[K-1:] = [cmb(n, K-1) for n in range(K-1, N)]

answer = (A * coef % MOD).sum() % MOD

coef = np.zeros(N, np.int64)

coef[:-K+1] = [cmb(n, K-1) for n in range(N-1, K-2, -1)]

answer -= (A * coef % MOD).sum() % MOD

print((answer%MOD))

# 53
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
A = lr()
A.sort()
MOD = 10**9 + 7
if K == 1:
    print((0))
    exit()


def cmb(n, k):
    # nCkを計算する
    k = min(k, n - k)
    return fac[n] * ifac[k] % MOD * ifac[n - k] % MOD


def make_tables(MOD, n):
    # 階乗テーブル、逆元の階乗テーブルを作成する
    fac = [1, 1]  # 階乗テーブル
    ifac = [1, 1]  # 逆元の階乗テーブル
    inverse = [0, 1]  # 逆元テーブル 0の階乗は1 0の逆元は0
    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % MOD)
        inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
        ifac.append((ifac[-1] * inverse[-1]) % MOD)
    return fac, ifac


fac, ifac = make_tables(MOD, 10**6)
answer = 0
for i in range(K - 1, N):
    # 最大値として何回登場するか、A[i] * i C (K-1)
    answer += A[i] * cmb(i, K - 1)
    answer %= MOD
for i in range(N - K + 1):
    # A[i] * (N-(i+1)) C (k-1)
    answer -= A[i] * cmb(N - (i + 1), K - 1)
    answer %= MOD
print((answer % MOD))
# 51

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
MOD = 10**9 + 7
# 組合せ nCr (MOD) 逆元を使う方法
def perm(n, k):
    if k > n or k < 0:
        return 0
    return fact[n] * fact_inv[n - k] % MOD


def cmb(n, k):
    if k < 0 or k > n:
        return 0
    return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD


def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**0.5 + 1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n - 1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n - 1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD - 2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


U = 10**5 + 100  # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
N, K = lr()
A = np.array(lr())
A.sort()
if K == 1:
    print((0))
    exit()
coef = np.zeros(N, np.int64)
coef[K - 1 :] = [cmb(n, K - 1) for n in range(K - 1, N)]
answer = (A * coef % MOD).sum() % MOD
coef = np.zeros(N, np.int64)
coef[: -K + 1] = [cmb(n, K - 1) for n in range(N - 1, K - 2, -1)]
answer -= (A * coef % MOD).sum() % MOD
print((answer % MOD))
# 53

+import numpy as np +MOD = 10**9 + 7 +# 組合せ nCr (MOD) 逆元を使う方法 +def perm(n, k): +    if k > n or k < 0: +        return 0 +    return fact[n] * fact_inv[n - k] % MOD + + +def cmb(n, k): +    if k < 0 or k > n: +        return 0 +    return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD + + +def cumprod(arr, MOD): +    L = len(arr) +    Lsq = int(L**0.5 + 1) +    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) +    for n in range(1, Lsq): +        arr[:, n] *= arr[:, n - 1] +        arr[:, n] %= MOD +    for n in range(1, Lsq): +        arr[n] *= arr[n - 1, -1] +        arr[n] %= MOD +    return arr.ravel()[:L] + + +def make_fact(U, MOD): +    x = np.arange(U, dtype=np.int64) +    x[0] = 1 +    fact = cumprod(x, MOD) +    x = np.arange(U, 0, -1, dtype=np.int64) +    x[0] = pow(int(fact[-1]), MOD - 2, MOD) +    fact_inv = cumprod(x, MOD)[::-1] +    return fact, fact_inv + + +U = 10**5 + 100  # 階乗テーブルの上限 +fact, fact_inv = make_fact(U, MOD) -A = lr() +A = np.array(lr()) -MOD = 10**9 + 7 - - -def cmb(n, k): -    # nCkを計算する -    k = min(k, n - k) -    return fac[n] * ifac[k] % MOD * ifac[n - k] % MOD - - -def make_tables(MOD, n): -    # 階乗テーブル、逆元の階乗テーブルを作成する -    fac = [1, 1]  # 階乗テーブル -    ifac = [1, 1]  # 逆元の階乗テーブル -    inverse = [0, 1]  # 逆元テーブル 0の階乗は1 0の逆元は0 -    for i in range(2, n + 1): -        fac.append((fac[-1] * i) % MOD) -        inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD) -        ifac.append((ifac[-1] * inverse[-1]) % MOD) -    return fac, ifac - - -fac, ifac = make_tables(MOD, 10**6) -answer = 0 -for i in range(K - 1, N): -    # 最大値として何回登場するか、A[i] * i C (K-1) -    answer += A[i] * cmb(i, K - 1) -    answer %= MOD -for i in range(N - K + 1): -    # A[i] * (N-(i+1)) C (k-1) -    answer -= A[i] * cmb(N - (i + 1), K - 1) -    answer %= MOD +coef = np.zeros(N, np.int64) +coef[K - 1 :] = [cmb(n, K - 1) for n in range(K - 1, N)] +answer = (A * coef % MOD).sum() % MOD +coef = np.zeros(N, np.int64) +coef[: -K + 1] = [cmb(n, K - 1) for n in range(N - 1, K - 2, -1)] +answer -= (A * coef % MOD).sum() % MOD -# 51 +# 53