#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)


class ModInt
{
public:
    static int _BM;
    long long int m_value;
    ModInt()
    {
        m_value = 0;
    }

    ModInt(int v)
    {
        m_value = (_LL) v;
        _mod();
    }

    ModInt(_LL v)
    {
        m_value = (_LL) v;
        _mod();
    }    

    ModInt(const ModInt &t)
    {
        m_value = t.getint();
    }

    const ModInt operator + (const ModInt &t) const 
    {
        ModInt ans(*this);
		return ans += t;
	}    

    const ModInt operator + (int t)  const 
    {
        ModInt ans(*this);
		return ans += t;
	}      

    const ModInt operator + (_LL t)  const 
    {
        ModInt ans(*this);
		return ans += t;
	}        

    const ModInt operator -  (const ModInt &t)  const 
    {
        ModInt ans(*this);
		return ans -= t;
	}    
    const ModInt operator - (int t)  const 
    {
        ModInt ans(*this);
		return ans -= t;
	}  
    const ModInt operator - (_LL t) const  
    {
        ModInt ans(*this);
		return ans -= t;
	}  

    const ModInt operator * (const ModInt &t)  const 
    {
        ModInt ans(*this);
		return ans *= t;
	}  
    const ModInt operator * (int t)  const 
    {
        ModInt ans(*this);
		return ans *= t;
	} 
    const ModInt operator * (_LL t)  const 
    {
        ModInt ans(*this);
		return ans *= t;
	} 

    const ModInt operator / (const ModInt &t)  const 
    {
        ModInt ans(*this);
		return ans /= t;
	}  
    const ModInt operator / (int t)  const 
    {
        ModInt ans(*this);
		return ans /= t;
	} 
    const ModInt operator / (_LL t)  const 
    {
        ModInt ans(*this);
		return ans /= t;
	}     

    bool operator == (int t)
    {
        return getint() == t;
    }

    ModInt& operator += ( const ModInt &t )
    {
        (*this) += t.getint();
        return (*this);
    }


    ModInt& operator *= ( const ModInt &t )
    {
        (*this) *= t.getint();
        return (*this);
    }

    ModInt& operator -= ( const ModInt &t )
    {
        (*this) -= t.getint();
        return (*this);
    }

    ModInt& operator += ( int v )
    {
        m_value += (v % _BM);
        if(m_value >= _BM) m_value -= _BM;
        return *this;
    }

    ModInt& operator -= ( int v )
    {
        m_value -= (v % _BM);
        if( m_value < 0 ) m_value += _BM;
        return *this;
    }

    ModInt& operator *= ( int v )
    {
        m_value *= (v % _BM);
        m_value %= _BM;
        if( m_value < 0 ) m_value += _BM;
        return *this;
    }

    ModInt& operator += ( _LL v )
    {
        m_value += (v % _BM);
        if(m_value >= _BM) m_value -= _BM;
        return *this;
    }

    ModInt& operator -= ( _LL v )
    {
        m_value -= (v % _BM);
        if( m_value < 0 ) m_value += _BM;
        return *this;
    }

    ModInt& operator *= ( _LL v )
    {
        m_value *= (v % _BM);
        m_value %= _BM;
        if( m_value < 0 ) m_value += _BM;
        return *this;
    }    

    static int modadd( int a, int b )
    {
        ModInt t(a);
        t += b;
        return t.getint();
    }

    ModInt& operator /= ( const ModInt &t )
    {
        (*this) /= t.getint();
        return (*this);
    }

    ModInt& operator /= ( int v )
    {
        (*this) *= reciprocal(v);
        return *this;
    }    

    ModInt& operator /= ( _LL v )
    {
        (*this) *= reciprocal(v);
        return *this;
    }    


    static int modminus( int a, int b )
    {
        ModInt t(a);
        t -= b;
        return t.getint();
    }    

    static int modmul( int a, int b )
    {
        ModInt t(a);
        t *= b;
        return t.getint();
    }

    static int modadd( _LL a, _LL b )
    {
        ModInt t(a);
        t += b;
        return t.getint();
    }

    static int modminus( _LL a, _LL b )
    {
        ModInt t(a);
        t -= b;
        return t.getint();
    }    

    static int modmul( _LL a, _LL b )
    {
        ModInt t(a);
        t *= b;
        return t.getint();
    }    

    // a^b;
    static int modpow(int a, int b)
    {
        return modpow((_LL) a, (_LL)b);
    }

    static int modpow(_LL a, _LL b)
    {
        ModInt ans(1);
        int heap[64];
        heap[0] = (a % _BM);
        for( int bit = 0; b >= (((_LL)1) << bit); bit++ )
        {
            if( bit > 0 ) heap[bit] = modmul( heap[bit - 1], heap[bit - 1] );
            if( b & (((_LL)1) << bit) )
            {
                ans *= heap[bit];
            }
        }
        return ans.getint();
    }

    static int reciprocal(int a)
    {
        return reciprocal((_LL) a);
    }

    static int reciprocal(_LL a)
    {
        _LL b = _BM, u = 1, v = 0;
        while (b) {
            _LL t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= _BM; 
        if (u < 0) u += _BM;
        return (int)u;
    }

    static int getCombination(_LL n, _LL r)
    {
        _LL ans;
        ans = 1;
        for(_LL i = 0; i < r; i++) ans = modmul(ans, n - i);
        _LL inv = 1;
        for(_LL i = 0; i < r; i++) inv = modmul(inv, i + 1);
        return modmul(ans, (_LL) reciprocal(inv));
    }

    static int combination(int n, int r)
    {
        int *fac = (int *)malloc(sizeof(int) * (n + 1));
        int *facinv = (int *)malloc(sizeof(int) * (n + 1));
        fac[0] = 1;
        for( int k = 1; k <= n; k++) fac[k] = modmul(k, fac[k - 1]);
        facinv[n] = reciprocal( fac[n] );
        for( int k = n ; k > 0; k--) facinv[k - 1] = modmul(k, facinv[k]);

        ModInt ans(fac[n]);
        ans *= facinv[r];
        ans *= facinv[n - r];

        free(fac);
        free(facinv);
        return ans.getint();
    }

    int getint() const
    {
        return (int) m_value;
    }


private:
    void _mod()
    {
        if( m_value < 0 )
        {
            m_value += _BM * (-m_value / _BM + 1);
        }
        m_value %= _BM;
    }
};

int ModInt::_BM = 1000000007;

class ModFactorial
{
public:
    int m_max;
    int *m_factorial;
    int *m_factorialinv;

    ModFactorial(int max)
    {
        m_max = max;
        m_factorial = (int*) malloc(sizeof(int) * m_max );
        m_factorialinv = (int*) malloc(sizeof(int) * m_max );
 
        m_factorial[0] = 1;
        for( int k = 1; k < m_max; k++) m_factorial[k] = ModInt::modmul(k, m_factorial[k - 1]);
        m_factorialinv[m_max - 1] = ModInt::reciprocal( m_factorial[m_max - 1] );
        for( int k = m_max - 1 ; k > 0; k--) m_factorialinv[k - 1] = ModInt::modmul(k, m_factorialinv[k]);
    }

    ~ModFactorial()
    {
        free(m_factorial);
        free(m_factorialinv);
    }

    int getFactorial(int n)
    {
        
        return m_factorial[n];
    }

    int getCombination(int n, int r)
    {
        ModInt ans(m_factorial[n]);
        ans *= m_factorialinv[r];
        ans *= m_factorialinv[n - r];
        return ans.getint();
    }
};


int main()
{
    int n, k;
    cin >> n >> k;
    int *a = new int[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    ModFactorial fp(n);
    ModInt ans = 0;
    for(int i = n - 1; i >= k - 1; i--)
    {
        ModInt tmp = a[i];
        tmp *= fp.getCombination(i, k - 1);   
        ans += tmp; 
    }

    rep(i, n)
    {
        if( n - i < k ) break;
        ModInt tmp = a[i];
        tmp *= fp.getCombination(n - i - 1, k - 1);   
        ans -= tmp; 
    }

    cout << ans.getint();
    delete a;
    return 0;    
}

Measured memory_bytes: 4188