#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<n; i++)
using namespace std;
using ll=long long;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int N; ll M;
	cin>>N>>M;
	vector<int> A(N);
	vector<ll> P(N+1);
	rep(i, 0, N) cin>>A[i];
	sort(begin(A), end(A));
	rep(i, 0, N) P[N-i-1]=P[N-i]+A[N-i-1];
	int l=0, r=A.back()*2;
	auto f=[&](int m) {
		ll n=0, s=0;
		rep(i, 0, N) {
			int k=lower_bound(begin(A), end(A), m-A[i])-begin(A);
			n+=N-k, s+=P[k];
		}
		return make_pair(n, s*2);
	};
	ll n, s;
	while(l<r) {
		int m=l+r+1>>1;
		tie(n,s)=f(m);
		if(n<=M) r=m-1;
		else l=m;
	}
	tie(n,s)=f(r);
	cout<<s-r*(n-M);
}