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


int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    vector<ll> b(n+1);
    b[0]=0;
    for (int i=0;i<n;i++) {
        b[i+1]=a[i]+b[i];
    }
    vector<ll> c(n);
    ll lx=0,rx=1e6;
    while (rx-lx>1) {
        ll mx=lx+(rx-lx)/2;
        ll sumc=0;
        for (int i=0;i<n;i++) {
            c[i]=n-(lower_bound(a.begin(),a.end(),mx-a[i])-a.begin());
            sumc+=c[i];
        }
        if (sumc>=m) lx=mx;
        else rx=mx;
    }
    ll sumc=0;
    for (int i=0;i<n;i++) {
        c[i]=n-(lower_bound(a.begin(),a.end(),lx-a[i])-a.begin());
        sumc+=c[i];
    }
    ll ans=lx*(m-sumc);
    for (int i=0;i<n;i++) ans+=c[i]*a[i]+(b[n]-b[n-c[i]]);
    cout << ans << endl;
}