Problem:
Score : 500 points

Problem Statement

Takahashi has come to a party as a special guest.
There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i.

Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0).
A handshake will be performed as follows:

Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).

Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.

However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:

Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q).

What is the maximum possible happiness after M handshakes?

Constraints

1 \leq N \leq 10^5

1 \leq M \leq N^2

1 \leq A_i \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N

Output

Print the maximum possible happiness after M handshakes.

Sample Input 1

5 3
10 14 19 34 33

Sample Output 1

202

Let us say that Takahashi performs the following handshakes:

In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.

In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.

In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.

Then, we will have the happiness of (34+34)+(34+33)+(33+34)=202.

We cannot achieve the happiness of 203 or greater, so the answer is 202.

Sample Input 2

9 14
1 3 5 110 24 21 34 5 3

Sample Output 2

1837

Sample Input 3

9 73
67597 52981 5828 66249 75177 64141 40773 79105 16076

Sample Output 3

8128170

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: u32 = 1_000_000_007;
const INF: usize = std::usize::MAX/2;

pub trait SetMinMax {
	fn setmin(&mut self, v: Self) -> bool;
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMinMax for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

// https://math314.hateblo.jp/entry/2015/05/07/014908
fn ntt(c: Vec<i64>, inv: bool, mo: i64, g: i64) -> Vec<i64>{
    let n = c.len();
    if n==1 {
        return c;
    }
    let c1: Vec<i64> = (0..n/2).map(|x| c[2*x]).collect();
	let c2: Vec<i64> = (0..n/2).map(|x| c[2*x+1]).collect();
	let r1 = ntt(c1, inv, mo, g);
    let r2 = ntt(c2, inv, mo, g);
    let mut ret = vec![0;n];
	let mut h = mod_pow(g,(mo-1)/(n as i64),mo);
	if inv {h = mod_inv(h,mo);}
	let mut base = 1;
    for i in 0..n {
		ret[i] = r1[i%(n/2)] + base * r2[i%(n/2)];
		ret[i] %= mo;
		base = base * h % mo;
    }
    ret
}

fn conv(mut a1: Vec<i64>, mut a2: Vec<i64>) -> Vec<i64> {
    let sz = a1.len()+a2.len();
    let mut n = 1;
	while sz>n {n*=2;}
	while a1.len()<n { a1.push(0);}
	while a2.len()<n { a2.push(0);}
	let mo = 2281701377;
	let g = 5;
	let f1 = ntt(a1.clone(),false,mo,g);
	let f2 = ntt(a2.clone(),false,mo,g);
	let c1: Vec<i64> = (0..n).map(|x| f1[x]*f2[x]%mo).collect();
	let ans = ntt(c1.clone(),true,mo,g);
	ans.iter().map(|x| x*mod_inv(n as i64,mo)%mo).collect::<Vec<i64>>()
}

fn mod_pow(mut a: i64, n: i64, mo: i64) -> i64{
	a %= mo;
	if a == 0 {
		return 0;
	}
	let mut lo = n;
	let mut ret = 1;
	let mut x = a;
	while lo > 0 {
		if lo % 2 == 1 {
			ret = ret * x % mo;
		}
		x = x * x % mo;
		lo /= 2;
	}
	ret
}

fn mod_inv(a: i64, mo: i64) -> i64{
	mod_pow(a,mo-2,mo)
}

fn solve() {
	let (n,m) = read!(usize,usize);
	let a = read!([usize]);
	let mut ma = 100000;
	let mut v = vec![0;ma+1];
	for i in 0..n {
		v[a[i]] += 1;
	}
	let ret = conv(v.clone(),v.clone());
	let mut ans = 0;
	let mut res = m as i64;
	for i in (0..2*ma+1).rev() {
		if ret[i]<=res {
			res -= ret[i];
			ans += ret[i]*(i as i64);
		}
		else{
			ans += res * (i as i64);
			break;
		}
	}
	println!("{}", ans);
}

fn run() {
    solve();
}