{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Maybe as Maybe
import qualified Data.Char as Char
import Control.Monad (replicateM, guard)
import Data.List (sortOn)
import Data.Ord (Down(..))
import qualified Data.Vector.Unboxed as Vector
import Data.Vector.Unboxed ((!))

main :: IO ()
main =
    print =<< runParser solve <$> B.getContents

solve :: Parser Int
solve = do
    nEatRed     <- parseInt
    nEatGreen   <- parseInt
    nRed        <- parseInt
    nGreen      <- parseInt
    nWhite      <- parseInt
    redApples   <- sortOn Down <$> replicateM nRed parseInt
    greenApples <- sortOn Down <$> replicateM nGreen parseInt
    whiteApples <- sortOn Down <$> replicateM nWhite parseInt
    let
        sumRed   = Vector.fromList $ 0 : cumulativeSum redApples
        sumGreen = Vector.fromList $ 0 : cumulativeSum greenApples
        sumWhite = Vector.fromList $ 0 : cumulativeSum whiteApples
        scores = do
            i <- [0..nEatRed]
            j <- [0..nEatGreen]
            let k = (nEatRed - i) + (nEatGreen - j)
            guard $ nWhite - k >= 0
            return $ (sumRed ! i) + (sumGreen ! j) + (sumWhite ! k)
    return $ maximum scores

cumulativeSum :: [Int] -> [Int]
cumulativeSum xs =
    scanl1 (+) xs

-------------------------------------------------------------------------------

newtype Parser a =
    Parser (B.ByteString -> (a, B.ByteString))

instance Functor Parser where
    fmap f (Parser parser) =
        Parser $ \input ->
            let (v, remainder) = parser input in
                (f v, remainder)

instance Applicative Parser where
    pure v =
        Parser $ \input ->
            (v, input)

    (Parser parser1) <*> (Parser parser2) =
        Parser $ \input ->
            let
                (f, remainder1) = parser1 input
                (v, remainder2) = parser2 remainder1
            in
                (f v, remainder2)

instance Monad Parser where
    return = pure

    (Parser parser1) >>= f =
        Parser $ \input ->
            let
                (v, remainder) = parser1 input
                Parser parser2 = f v
            in
                parser2 remainder

consumeSpace :: Parser ()
consumeSpace =
    Parser $ \input ->
        ((), B.dropWhile Char.isSpace input)

parseInt_ :: Parser Int
parseInt_ =
    Parser $ \input ->
        Maybe.fromJust (B.readInt input)

parseInt :: Parser Int
parseInt =
    consumeSpace *> parseInt_

runParser :: Parser a -> B.ByteString -> a
runParser (Parser parser) input =
    fst $ parser input

-------------------------------------------------------------------------------
