import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sortBy)

main :: IO ()
main = do
  (n : m : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- sortBy (flip compare) . map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    a0 = head as :: Int
    countAndSumGE :: Int -> (Int, Int)
    countAndSumGE k = fst . fst . foldr step (((0, 0), (0, 0)), as) $ as
      where
        step :: Int -> (((Int, Int), (Int, Int)), [Int]) -> (((Int, Int), (Int, Int)), [Int])
        step x (((c, s), (d, t)), ys) = (((c + c', s + s'), (d', t')), sf)
          where
            (pf, sf) = span (k - x <=) ys
            (u, v) = ((,) <$> length <*> sum) pf
            d' = d + u
            c' = d'
            t' = t + v
            s' = x * d' + t'
    sumGE :: Int -> Int
    sumGE = snd . countAndSumGE
    sumMapGE :: (Int -> Int) -> Int -> Int
    sumMapGE f k = fst . fst . foldr step ((0, 0), as) $ as
      where
        step x ((c, d), ys) = ((c + d', d'), sf)
          where
            (pf, sf) = span (k - x <=) ys
            d' = d + sum (map (f . (x +)) pf)
    countGE :: Int -> Int
    countGE k = fst . fst . foldr step ((0, 0), as) $ as
      where
        step x ((c, d), ys) = ((c + d', d'), sf)
          where
            (pf, sf) = span (k - x <=) ys
            d' = d + length pf
    k = unsafeBinaryMaxInt ((m <=) . countGE) (0, a0 * a0) :: Int
    (c, s) = countAndSumGE (succ k)
  print $ s + k * (m - c)

unsafeBinaryMaxInt :: (Int -> Bool) -> (Int, Int) -> Int
unsafeBinaryMaxInt p = fst . until ((==) <$> succ . fst <*> snd) halve
  where
    halve (i, j) | p m       = (m, j)
                 | otherwise = (i, m)
      where
        m = (i + j) `div` 2

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
