Language: C++

#include <bits/stdc++.h>
using namespace std;

const long long MAX = 100000;
const long long MOD = 1000000000 + 7;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 
long long COM(long long n, long long k) {
  if (n < 0 || k < 0 || k > n) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  
  COMinit();
  
  long long N, K;
  cin >> N >> K;
  
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  sort(A.begin(), A.end());
  
  vector<pair<pair<long long, long long>, long long>> data();
  
  long long a, b;
  a = 0;
  b = 0;
  long long t = - MOD;
  
  for(int i = 0; i < N; i++) {
    if (A[i] == t) {
      b++;
    }
    else {
      b++;
      data.push_back({{b, a}, A[i]});
      t = A[i];
      a = b;
    }
  }
  
  long long ans1 = 0;
  
  for (int i = 0; i < data.size(); i++) {
    long long x = data[i].first.first;
    long long y = data[i].first.second;
    long long p = data[i].second;
    ans1 += (MOD + COM(x, K) - COM(y, K)) * p;
    ans1 %= MOD;
  }
  
  cout << ans1 << endl;
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:59: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   39 |   vector<pair<pair<long long, long long>, long long>> data();
      |                                                           ^~
a.cc:52:12: error: request for member 'push_back' in 'data', which is of non-class type 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >()'
   52 |       data.push_back({{b, a}, A[i]});
      |            ^~~~~~~~~
a.cc:60:28: error: request for member 'size' in 'data', which is of non-class type 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >()'
   60 |   for (int i = 0; i < data.size(); i++) {
      |                            ^~~~
a.cc:61:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |     long long x = data[i].first.first;
      |                         ^
a.cc:61:27: error: request for member 'first' in '*(data + ((sizetype)i))', which is of non-class type 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >()'
   61 |     long long x = data[i].first.first;
      |                           ^~~~~
a.cc:62:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   62 |     long long y = data[i].first.second;
      |                         ^
a.cc:62:27: error: request for member 'first' in '*(data + ((sizetype)i))', which is of non-class type 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >()'
   62 |     long long y = data[i].first.second;
      |                           ^~~~~
a.cc:63:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   63 |     long long p = data[i].second;
      |                         ^
a.cc:63:27: error: request for member 'second' in '*(data + ((sizetype)i))', which is of non-class type 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >()'
   63 |     long long p = data[i].second;
      |                           ^~~~~~