Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

#define MAX 1e7+1    //nCrのnの最大値+1

ll fac[MAX], inv[MAX], finv[MAX];

void COMinit(ll mod) {
    fac[0] = 1, finv[0] = 1;
    fac[1] = 1, inv[1] = 1, finv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - (inv[mod % i] * (mod/i) % mod) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(ll n, ll k, ll mod) {
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * finv[k] % mod * finv[n-k] % mod;
}

int main() {
    ll n, k, mod = 1e9+7;    cin >> n >> k;
    ll *a = new ll[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a+n);
    COMinit(mod);

    ll ans = 0;
    for (int i = 0; i < n-k+1; i++) {
        ans -= a[i] * COM(n-i-1, k-1, mod) % mod;
        ans %= mod;
    }
    for (ll i = k-1; i <= n-1; i++) {
        ans += a[i] * COM(i, k-1, mod) % mod;
        ans %= mod;
    }

    ans = (mod + ans) % mod;

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc:8:16: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
a.cc:10:8: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |        ^~~
a.cc:8:16: error: could not convert '(1.0e+7 + (double)1)' from 'double' to 'long unsigned int'
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
      |                |
      |                double
a.cc:10:8: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |        ^~~
a.cc:8:16: error: size of array 'fac' has non-integral type 'double'
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
a.cc:10:8: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |        ^~~
a.cc:8:16: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
a.cc:10:18: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |                  ^~~
a.cc:8:16: error: could not convert '(1.0e+7 + (double)1)' from 'double' to 'long unsigned int'
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
      |                |
      |                double
a.cc:10:18: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |                  ^~~
a.cc:8:16: error: size of array 'inv' has non-integral type 'double'
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
a.cc:10:18: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |                  ^~~
a.cc:8:16: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
a.cc:10:29: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |                             ^~~
a.cc:8:16: error: could not convert '(1.0e+7 + (double)1)' from 'double' to 'long unsigned int'
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
      |                |
      |                double
a.cc:10:29: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |                             ^~~
a.cc:8:16: error: size of array 'finv' has non-integral type 'double'
    8 | #define MAX 1e7+1    //nCrのnの最大値+1
      |             ~~~^~
a.cc:10:29: note: in expansion of macro 'MAX'
   10 | ll fac[MAX], inv[MAX], finv[MAX];
      |                             ^~~