import Control.Applicative import Data.List (sortBy) import Data.Int import Data.Array import qualified Data.Vector as V import Debug.Trace readInts :: IO [Int64] readInts = map read . words <$> getLine main = do [n, v] <- readInts cs <- readInts let comp (x,y) (x',y') = compare (x*y') (x'*y) total = sum cs cs' = V.fromList . sortBy comp $ zip (scanl1 (+) cs) [1..] inf = 1001001001001001001001001 dp x | x <= 0 = 0 | otherwise = table ! (n,x) where table = array ((0,0),(n,x)) [((i, j), f i j) | i <- [0..n], j <- [0..x]] f _ 0 = 0 f 0 _ = inf f i j = minimum [table!(i,j-1) + a, table!(i-1,j), if j-b >= 0 then table!(i,j-b) + a else inf] where (a, b) = cs' V.! (fromIntegral i-1) f i = a * ((v-n) `div` b) + dp ((v-n) `mod` b) where (a, b) = cs' V.! i in print $ if v < n then total else total + minimum (map f [0..fromIntegral n-1])