Language: C++

#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



std::int64_t power(std::int64_t n, std::int64_t p, std::int64_t m){
  std::int64_t ret = 1;
  while(p>0){
    if(p & 1) (ret *= n) %= m;
    (n *= n) %= m;
    p >>= 1;
  }
  return ret;
}


std::int64_t mod_inv(std::int64_t n, std::int64_t p){return power(n,p-2,p);}


template <int MOD, int PRIM_ROOT, bool INVERSE = false>
std::vector<int64_t> number_theory_transform(std::vector<int64_t> f){
  const int n = f.size();
  assert((n & (n-1)) == 0); // データ数は2の冪乗個
  
  const int p = __builtin_ctz(n);
  
  for(int i = 0; i < n; ++i){
    int j = 0;
    for(int k = 0; k < p; ++k) j |= (i >> k & 1) << (p-1-k);
    if(i < j) std::swap(f[i], f[j]);
  }

  for(auto &x : f) if(x > MOD) x %= MOD;

  const int64_t t = (MOD - 1) * mod_inv(n, MOD) % MOD;
  int64_t h = power(PRIM_ROOT, t, MOD);
  
  if(INVERSE) h = mod_inv(h, MOD);

  if(p > 0){
    std::vector<int64_t> base(p);
    base[p-1] = h;
    for(int i = p-2; i >= 0; --i) base[i] = base[i+1] * base[i+1] % MOD;
    
    for(int b = 1; b < n; b <<= 1){
      int64_t w = 1;
    
      for(int i = 0; i < b; ++i){
        for(int j = 0; j < n; j += 2*b){
          const int k = i + j;
          const auto s = f[k];
          const auto t = f[k+b] * w % MOD;

          f[k] = s + t;
          if(f[k] >= MOD) f[k] -= MOD;
        
          f[k+b] = s - t;
          if(f[k+b] < 0) f[k+b] += MOD;
        }

        (w *= base[__builtin_ctz(b)]) %= MOD;
      }
    }
  }

  if(INVERSE){
    const int64_t t = mod_inv(n, MOD);
    for(auto &x : f) (x *= t) %= MOD;
  }

  return f;
}

template <int MOD, int PRIM_ROOT>
std::vector<int64_t> ntt_convolution(std::vector<int64_t> f, std::vector<int64_t> g){
  const int m = f.size() + g.size() - 1;
  int n = 1;
  while(n < m) n *= 2;

  std::vector<int64_t> f2(n), g2(n);

  for(int i = 0; i < (int)f.size(); ++i) f2[i] = f[i];
  for(int i = 0; i < (int)g.size(); ++i) g2[i] = g[i];
 
  f2 = number_theory_transform<MOD, PRIM_ROOT>(f2);
  g2 = number_theory_transform<MOD, PRIM_ROOT>(g2);
  
  std::vector<int64_t> ret(n);
  for(int i = 0; i < n; ++i) ret[i] = f2[i] * g2[i] % MOD;
  ret = number_theory_transform<MOD, PRIM_ROOT, true>(ret);
  
  return ret;
}

const int MAX = 100000;

int main(){
  LLI N, M;
  while(cin >> N >> M){
    vector<LLI> A(N); cin >> A;
    sort(RALL(A));

    vector<LLI> count(MAX+1);
    for(auto x : A) count[x] += 1;

    auto res = ntt_convolution<1224736769,3>(count, count);

    
    LLI ans = 0;

    REV(i,2*MAX,1){
      int k = res[i];

      if(M > k){
        ans += i * k;
        M -= k;
      }else{
        ans += i * M;
        break;
      }
    }

    cout << ans << endl;
  }


  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:149:46: error: could not convert 'count' from 'vector<long long int>' to 'vector<long int>'
  149 |     auto res = ntt_convolution<1224736769,3>(count, count);
      |                                              ^~~~~
      |                                              |
      |                                              vector<long long int>