import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val _A = Array.fill[Int](N+1)(Int.MaxValue)
  for (i <- 1 to N) {
    _A(i) = in.next().toInt
  }

  //
  val A = _A.sorted.reverse

  var ans = 0L
  var base = 0L
  var b = 1 // 握手の回数
  var i = 1
  breakable {
    while (true) {
      val now = A(i)
      ans += now * 2
      ans += now * (i-1) * 2
      ans += base

      if (b + i * 2 + 1 <= M) {
        base += now * 2
        b += i * 2 + 1
        i += 1
      }
      else
        break
    }
  }

//  println(ans)

  var h = M - b
  i += 1
//  println(h, i)
  var p = 1
  breakable {
    while (h > 0) {
      if (h >= 2) {
        ans += (A(p) + A(i)) * 2
        h -= 2
        p += 1
      }
      else if (h == 1) {
        ans += A(p) + A(i)
        break
      }
    }
  }
  
  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
