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

ll count(vector<ll> a, ll n, ll v) {
    ll tot = 0;
	for (ll i = 0; i < n; ++i) {
		tot += n - (lower_bound(a.begin(), a.end(), v - a[i]) - a.begin());
	}
	return tot;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n,0);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<ll> s(n+1,0);
    for (ll i = 0; i < n; ++i) {
        s[i+1] = s[i] + a[n - 1- i];
    }

	ll mi = 0;
	for (ll i=40; i>=0; i--) {
        if (count(a, n, mi+(1LL<<i)) >=m ) {
            mi += 1LL<<i;
        }
    }

	ll num=0;
	ll ret=0;
    for (ll i = 0; i < n; ++i) {
		ll x = n - (lower_bound(a.begin(), a.end(), mi - a[i]) - a.begin());
		num += x;
		ret += a[i]*x + s[x];		
	}

	ret -= (num-m)*mi;
	cout<<ret<<endl;
}