Language: C++

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cassert>

#include<cmath>
#include<functional>
#include<algorithm>

#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<bitset>
#include<tuple>

#define TEST {IS_TEST=true;}
#define fi first
#define se second
#define pb(x) {push_back(x);}

using namespace std;
using ll = int_fast64_t;
using v_b = vector <bool>;
using v_ll = vector <ll>;
using str = string;
using v_str = vector <string>;
using p_ll = pair < ll,ll >;
using vv_b = vector < v_b >;
using vv_ll = vector < v_ll >;
using vp_ll = vector < p_ll >;
using vvv_ll = vector < vv_ll >;
using vvp_ll = vector < vp_ll >;

using ld = long double;
using v_ld = vector <ld>;
using vv_ld = vector<v_ld>;

bool IS_TEST=false;
ll ll_min64=1LL<<63;
ll ll_max64=~ll_min64;
ll ll_min32=1LL<<31;
ll ll_max32=~ll_min32;

ll MOD = 1000000007;

/*displaying functions for debug*/
template<class T> void show2(const T &x){cout << x;}
template<class T1,class T2> void show2(const pair<T1,T2> &x){
  cout << "{" << show2(x.first) << "," << show2(x.second) << "}";
}
template<class T> void show(const T &x){
  if (!IS_TEST) return;
  show2(x); cout <<endl;
}
template<class T> void v_show(const T &v, ll n=-1){
  if (!IS_TEST) return;
  auto itr=v.begin(); ll m=n;
  while(itr!=v.end() && m!=0 ){ show2(*itr); cout << " "; itr++; m--;}
  cout << endl;
}
template<class T> void vv_show(const T &v, ll n=-1){
  if (!IS_TEST) return;
  cout << "--------------------------------\n";
  auto itr=v.begin(); ll m=n;
  while(itr!=v.end() && m!=0 ){ v_show(*itr,n); itr++; m--;}
  cout << "--------------------------------" << endl;
}
/*--------------------------------*/

/*loading integers*/
void load(ll& x1){ cin >> x1; }
void load(ll& x1,ll& x2){ cin >> x1 >> x2; }
void load(ll& x1,ll& x2,ll& x3){ cin >> x1 >> x2 >> x3; }
void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
void v_load(ll n, v_ll& v1, ll head=0, ll tail=0, ll init=0){
    ll m=n+head+tail; v1.assign(m,init);
    for (ll i=0;i<n;i++){ cin >> v1[i+head]; }
}
void v_load(ll n, v_ll& v1 ,v_ll& v2, ll head=0, ll tail=0, ll init=0){
    ll m=n+head+tail; v1.assign(m,init); v2.assign(m,init);
    for (ll i=0;i<n;i++){ cin >> v1[i+head] >> v2[i+head]; }
}
void v_load(ll n, v_ll& v1 ,v_ll& v2, v_ll& v3, ll head=0, ll tail=0, ll init=0){
    ll m=n+head+tail; v1.assign(m,init); v2.assign(m,init); v3.assign(m,init);
    for (ll i=0;i<n;i++){ cin >> v1[i+head] >> v2[i+head] >> v3[i+head]; }
}
void v_load(ll n, v_ll& v1 ,v_ll& v2, v_ll& v3, v_ll& v4, ll head=0, ll tail=0, ll init=0){
    ll m=n+head+tail; v1.assign(m,init); v2.assign(m,init); v3.assign(m,init); v4.assign(m,init);
    for (ll i=0;i<n;i++){ cin >> v1[i+head] >> v2[i+head] >> v3[i+head] >> v4[i+head]; }
}
/*--------------------------------*/

v_ll ll_mg(ll x1=ll_max64, ll x2=ll_max64, ll x3=ll_max64, ll x4=ll_max64){
    v_ll x{x1,x2,x3,x4};
    sort(x.begin(),x.end());
    return x;
}

template<class T> void ch_max(T& x,const T& y){ if (x>=y) return; x=y; }
template<class T> void ch_min(T& x,const T& y){ if (x<=y) return; x=y; }
template<class T,class S> void ch_max(T& x,S& xx,const T& y,const S& yy){
  if (x>=y) return; x=y; xx=yy;
}
template<class T,class S> void ch_min(T& x,S& xx,const T& y,const S& yy){
  if (x<=y) return; x=y; xx=yy;
}

template<class T> void quit(T x){cout << x << endl; exit(0);}

ll rem(ll x,ll y){ ll z=x%y; return z>=0?z:z+y; }

ll N,M,ans;
v_ll A,B;


v_ll fft(const v_ll& x, bool inv=false, ll n_depth=-1, const ll mod){
    if (n_depth<0) {n_depth=0; while (1LL<<++n_depth < x.size());}
    ll n=1LL<<n_depth;
    v_ll arr(n,0);
    v_ll temp(n,0);
    v_ll w(24,0);

    switch(mod){
        case 998244353:
            w[23] = inv?128805723:31; break;
        case 897581057:
            w[23] = inv?139623720:45; break;
        case 880803841:
            w[23] = inv?567721907:211; break;
        default:
            cerr << "incorrect modulo in fft\n";
            exit(1);
    }
    for (ll i=22;i>=0;i--){ w[i]=w[i+1]*w[i+1]%mod; }
    for (ll i=0;i<x.size();i++){ arr[i]=x[i]; }

    ll depth,cell,n_cell;
    ll div=1;
    for (depth=1,cell=n,n_cell=1;cell>1;depth++,cell>>=1,n_cell<<=1){
        ll mul=1;
        if (inv) {div*=(mod+1)>>1; div%=mod;}
        for (ll i=0;i<n;i++){ temp[i]=arr[i]; }
        for (ll i=0;i<n_cell;i++){
            for (ll j=0;j<cell/2;j++){
                arr[i*cell/2+j]=(temp[i*cell+j]+mul*temp[i*cell+j+cell/2])%mod;
                arr[i*cell/2+j+n/2]=(temp[i*cell+j]+(mod-mul)*temp[i*cell+j+cell/2])%mod;
            }
            mul=mul*w[depth]%mod;
        }
    }
    if (inv) for (ll i=0;i<n;i++){ arr[i]*=div; arr[i]%=mod; }
    return arr;
}
v_ll convolute(const v_ll& x,const v_ll& y, ll mod=0){
    ll n_depth=0;
    vv_ll z(3,v_ll());
    const v_ll mods={998244353,897581057,880803841};
    while (1LL<<n_depth < max(x.size(),y.size()))n_depth++;
    n_depth++;
    
    for (ll m=0;m<3;m++){
        v_ll xx=fft(x,false,n_depth,mods[m]);
        v_ll yy=fft(y,false,n_depth,mods[m]);
        v_ll zz(1LL<<n_depth,0);
        for (ll i=0;i<xx.size();i++) { zz[i]=(xx[i]*yy[i])%mods[m]; }
        z[m]=fft(zz,true,n_depth,mods[m]);
        if (mod==998244353)return z[0];
    }
    ll inv1=523588941;
    ll inv2=220201354;
    v_ll ret(1LL<<n_depth,0);
    for (ll i=0;i<1LL<<n_depth;i++){
        v_ll v(3,0);
        v[0] = z[0][i];
        v[1] = (z[1][i]-v[0]) %mods[1] *inv1 %mods[1];
        if (v[1]<0) v[1]+=mods[1];
        v[2] = (z[2][i]-v[0]-mods[0]*v[1]%mods[2]) %mods[2] *inv2 %mods[2];
        if (v[2]<0) v[2]+=mods[2];
        if (mod==0){
            ret[i]=v[0]+v[1]*mods[0]+v[2]*mods[0]*mods[1];
            if (v[2]>=mods[2]/2)
                ret[i]-=mods[0]*mods[1]*mods[2];
        }else{
            ret[i]=v[0]+v[1]*mods[0]%mod+v[2]*mods[0]%mod*mods[1]%mod;
            if (v[2]>=mods[2]/2)
                ret[i]-=mods[0]*mods[1]%mod*mods[2]%mod;
                if (ret[i]<0)ret[i]+=mod;
        }
    }
    return ret;
}

ll max(ll x,ll y){ return x>y?x:y;}
ll min(ll x,ll y){ return x<y?x:y;}

int main(){
    load(N,M);
    v_load(N,A);
    B.assign(100001,0);

    for (ll i=0;i<N;i++){
      B[A[i]]++;
    }

    v_ll a=convolute(B,B);
    ll remain=M;
    ans=0;

    for (ll i=200000;i>=0;i--){
      ll x=a[i];
      ans+=i*min(remain,x);
      remain-=x;
      if (remain<=0)break;
    }
    cout << ans << endl;
}




Compiler output:
a.cc:28:12: error: 'int_fast64_t' does not name a type
   28 | using ll = int_fast64_t;
      |            ^~~~~~~~~~~~
a.cc:30:22: error: 'll' was not declared in this scope
   30 | using v_ll = vector <ll>;
      |                      ^~
a.cc:30:24: error: template argument 1 is invalid
   30 | using v_ll = vector <ll>;
      |                        ^
a.cc:30:24: error: template argument 2 is invalid
a.cc:33:21: error: 'll' was not declared in this scope
   33 | using p_ll = pair < ll,ll >;
      |                     ^~
a.cc:33:24: error: 'll' was not declared in this scope
   33 | using p_ll = pair < ll,ll >;
      |                        ^~
a.cc:33:27: error: template argument 1 is invalid
   33 | using p_ll = pair < ll,ll >;
      |                           ^
a.cc:33:27: error: template argument 2 is invalid
a.cc:35:24: error: 'v_ll' was not declared in this scope
   35 | using vv_ll = vector < v_ll >;
      |                        ^~~~
a.cc:35:29: error: template argument 1 is invalid
   35 | using vv_ll = vector < v_ll >;
      |                             ^
a.cc:35:29: error: template argument 2 is invalid
a.cc:36:24: error: 'p_ll' was not declared in this scope
   36 | using vp_ll = vector < p_ll >;
      |                        ^~~~
a.cc:36:29: error: template argument 1 is invalid
   36 | using vp_ll = vector < p_ll >;
      |                             ^
a.cc:36:29: error: template argument 2 is invalid
a.cc:37:25: error: 'vv_ll' was not declared in this scope
   37 | using vvv_ll = vector < vv_ll >;
      |                         ^~~~~
a.cc:37:31: error: template argument 1 is invalid
   37 | using vvv_ll = vector < vv_ll >;
      |                               ^
a.cc:37:31: error: template argument 2 is invalid
a.cc:38:25: error: 'vp_ll' was not declared in this scope
   38 | using vvp_ll = vector < vp_ll >;
      |                         ^~~~~
a.cc:38:31: error: template argument 1 is invalid
   38 | using vvp_ll = vector < vp_ll >;
      |                               ^
a.cc:38:31: error: template argument 2 is invalid
a.cc:45:1: error: 'll' does not name a type; did you mean 'ld'?
   45 | ll ll_min64=1LL<<63;
      | ^~
      | ld
a.cc:46:1: error: 'll' does not name a type; did you mean 'ld'?
   46 | ll ll_max64=~ll_min64;
      | ^~
      | ld
a.cc:47:1: error: 'll' does not name a type; did you mean 'ld'?
   47 | ll ll_min32=1LL<<31;
      | ^~
      | ld
a.cc:48:1: error: 'll' does not name a type; did you mean 'ld'?
   48 | ll ll_max32=~ll_min32;
      | ^~
      | ld
a.cc:50:1: error: 'll' does not name a type; did you mean 'ld'?
   50 | ll MOD = 1000000007;
      | ^~
      | ld
a.cc:61:43: error: 'll' has not been declared
   61 | template<class T> void v_show(const T &v, ll n=-1){
      |                                           ^~
a.cc: In function 'void v_show(const T&, int)':
a.cc:63:23: error: 'll' was not declared in this scope; did you mean 'ld'?
   63 |   auto itr=v.begin(); ll m=n;
      |                       ^~
      |                       ld
a.cc:64:25: error: 'm' was not declared in this scope
   64 |   while(itr!=v.end() && m!=0 ){ show2(*itr); cout << " "; itr++; m--;}
      |                         ^
a.cc: At global scope:
a.cc:67:44: error: 'll' has not been declared
   67 | template<class T> void vv_show(const T &v, ll n=-1){
      |                                            ^~
a.cc: In function 'void vv_show(const T&, int)':
a.cc:70:23: error: 'll' was not declared in this scope; did you mean 'ld'?
   70 |   auto itr=v.begin(); ll m=n;
      |                       ^~
      |                       ld
a.cc:71:25: error: 'm' was not declared in this scope
   71 |   while(itr!=v.end() && m!=0 ){ v_show(*itr,n); itr++; m--;}
      |                         ^
a.cc: At global scope:
a.cc:77:6: error: variable or field 'load' declared void
   77 | void load(ll& x1){ cin >> x1; }
      |      ^~~~
a.cc:77:11: error: 'll' was not declared in this scope; did you mean 'ld'?
   77 | void load(ll& x1){ cin >> x1; }
      |           ^~
      |           ld
a.cc:77:15: error: 'x1' was not declared in this scope; did you mean 'y1'?
   77 | void load(ll& x1){ cin >> x1; }
      |               ^~
      |               y1
a.cc:78:6: error: variable or field 'load' declared void
   78 | void load(ll& x1,ll& x2){ cin >> x1 >> x2; }
      |      ^~~~
a.cc:78:11: error: 'll' was not declared in this scope; did you mean 'ld'?
   78 | void load(ll& x1,ll& x2){ cin >> x1 >> x2; }
      |           ^~
      |           ld
a.cc:78:15: error: 'x1' was not declared in this scope; did you mean 'y1'?
   78 | void load(ll& x1,ll& x2){ cin >> x1 >> x2; }
      |               ^~
      |               y1
a.cc:78:18: error: 'll' was not declared in this scope; did you mean 'ld'?
   78 | void load(ll& x1,ll& x2){ cin >> x1 >> x2; }
      |                  ^~
      |                  ld
a.cc:78:22: error: 'x2' was not declared in this scope
   78 | void load(ll& x1,ll& x2){ cin >> x1 >> x2; }
      |                      ^~
a.cc:79:6: error: variable or field 'load' declared void
   79 | void load(ll& x1,ll& x2,ll& x3){ cin >> x1 >> x2 >> x3; }
      |      ^~~~
a.cc:79:11: error: 'll' was not declared in this scope; did you mean 'ld'?
   79 | void load(ll& x1,ll& x2,ll& x3){ cin >> x1 >> x2 >> x3; }
      |           ^~
      |           ld
a.cc:79:15: error: 'x1' was not declared in this scope; did you mean 'y1'?
   79 | void load(ll& x1,ll& x2,ll& x3){ cin >> x1 >> x2 >> x3; }
      |               ^~
      |               y1
a.cc:79:18: error: 'll' was not declared in this scope; did you mean 'ld'?
   79 | void load(ll& x1,ll& x2,ll& x3){ cin >> x1 >> x2 >> x3; }
      |                  ^~
      |                  ld
a.cc:79:22: error: 'x2' was not declared in this scope
   79 | void load(ll& x1,ll& x2,ll& x3){ cin >> x1 >> x2 >> x3; }
      |                      ^~
a.cc:79:25: error: 'll' was not declared in this scope; did you mean 'ld'?
   79 | void load(ll& x1,ll& x2,ll& x3){ cin >> x1 >> x2 >> x3; }
      |                         ^~
      |                         ld
a.cc:79:29: error: 'x3' was not declared in this scope
   79 | void load(ll& x1,ll& x2,ll& x3){ cin >> x1 >> x2 >> x3; }
      |                             ^~
a.cc:80:6: error: variable or field 'load' declared void
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |      ^~~~
a.cc:80:11: error: 'll' was not declared in this scope; did you mean 'ld'?
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |           ^~
      |           ld
a.cc:80:15: error: 'x1' was not declared in this scope; did you mean 'y1'?
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |               ^~
      |               y1
a.cc:80:18: error: 'll' was not declared in this scope; did you mean 'ld'?
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |                  ^~
      |                  ld
a.cc:80:22: error: 'x2' was not declared in this scope
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |                      ^~
a.cc:80:25: error: 'll' was not declared in this scope; did you mean 'ld'?
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |                         ^~
      |                         ld
a.cc:80:29: error: 'x3' was not declared in this scope
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |                             ^~
a.cc:80:32: error: 'll' was not declared in this scope; did you mean 'ld'?
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |                                ^~
      |                                ld
a.cc:80:36: error: 'x4' was not declared in this scope
   80 | void load(ll& x1,ll& x2,ll& x3,ll& x4){ cin >> x1 >> x2 >> x3 >> x4; }
      |                                    ^~
a.cc:81:6: error: variable or field 'v_load' declared void
   81 | void v_load(ll n, v_ll& v1, ll head=0, ll tail=0, ll init=0){
      |      ^~~~~~
a.cc:81:13: error: 'll' was not declared in this scope; did you mean 'ld'?
   81 | void v_load(ll n, v_ll& v1, ll head=0, ll tail=0, ll init=0){
      |             ^~
      |             ld
a.cc:81:19: error: 'v_ll' was not declared in this scope; did you mean 'v_ld'?
   81 | void v_load(ll n, v_ll& v1, ll head=0, ll tail=0, ll init=0){
      |                   ^~~~
      |                   v_ld
a.cc:81:25: error: 'v1' was not declared in this scope; did you mean '__pstl::execution::v1'?
   81 | void v_load(ll n, v_ll& v1, ll head=0, ll tail=0, ll init=0){
      |                         ^~
      |                         __pstl::execution::v1
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/14/algorithm:86,
                 from a.cc:9:
/usr/include/c++/14/pstl/execution_defs.h:19:18: note: '__pstl::execution::v1' declared here
   19 | inline namespace v1
      |                  ^~
a.cc:81:29: error: 'll' was not declared in this scope; did you mean 'ld'?
   81 | void v_load(ll n, v_ll& v1, ll head=0, ll tail=0, ll init=0){
      |                             ^~
      |                             ld
a.cc:81:40: error: 'll' was not declared in this scope; did you mean 'ld'?
   81 | void v_load(ll n, v_ll& v1, ll head=0, ll tail=0, ll init=0){
      |                                        ^~
      |                                        ld
a.cc:81:51: error: 'll' was not declared in this scope; did you mean 'ld'?
   81 | void v_load(ll n, v_ll& v1, ll head=0, ll tail=0, ll init=0){
      |                                                   ^~
      |                                                   ld
a.cc:85:6: error: variable or field 'v_load' declared void
   85 | void v_load(ll n, v_ll& v1 ,v_ll& v2, ll head=0, ll tail=0, ll init=0){
      |      ^~~~~~
a.cc:85:13: error: 'll' was not declared in this scope; did you mean 'ld'?
   85 | void v_load(ll n, v_ll& v1 ,v_ll& v2, ll head=0, ll tail=0, ll init=0){
      |             ^~
      |             ld
a.cc:85: