Marc's Cakewalk

  • + 0 comments

    Haskell

    module Main where
    
    import Data.List (sortBy)
    
    solve :: [Int] -> Int
    solve cs = go 1 cs' 0
      where
        cs' = sortBy (flip compare) cs
        go _ [] acc = acc
        go p (c : cs) acc = go (p * 2) cs (acc + p * c)
    
    main :: IO ()
    main = getLine >> getLine >>= print . solve . map read . words