Problem:
Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74

Solution in Haskell (GHC 7.10.3) (judge verdict: Runtime Error)

import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
  [x, y, a, b, c] <- readInt
  p               <- readInt
  q               <- readInt
  r               <- readInt
  print $ solve x y p q r

solve :: Int -> Int -> [Int] -> [Int] -> [Int] -> Int
solve x y p q r = g p' q' r' x y 0
 where
  p' = take x $ sortOn Down p
  q' = take y $ sortOn Down q
  r' = take (x + y) $ (sortOn Down r ++ repeat 0)

f _ 0 _ 0 _ acc = acc

f _ 0 (q : qs) y (r : rs) acc | q >= r    = f [] 0 qs (y - 1) (r : rs) (acc + q)
                              | otherwise = f [] 0 (q : qs) (y - 1) rs (acc + r)

f (p : ps) x _ 0 (r : rs) acc
  | p >= r    = f ps (x - 1) [] 0 (r : rs) (acc + p)
  | otherwise = f (p : ps) (x - 1) [] 0 rs (acc + r)

f (p : ps) x (q : qs) y (r : rs) acc
  | p >= q && p >= r = f ps (x - 1) (q : qs) y (r : rs) (acc + p)
  | q >= p && q >= r = f (p : ps) x qs (y - 1) (r : rs) (acc + q)
  | r >= p && p >= q = f (p : ps) x (q : qs) (y - 1) rs (acc + r)
  | otherwise        = f (p : ps) (x - 1) (q : qs) y rs (acc + r)

g _  _  _  0 0 acc = acc

g ps qs [] x y acc = acc + sum (take x ps) + sum (take y qs)

g _ (q : qs) (r : rs) 0 y acc | q >= r    = g [] qs (r : rs) 0 (y - 1) (acc + q)
                              | otherwise = g [] (q : qs) rs 0 (y - 1) (acc + r)

g (p : ps) _ (r : rs) x 0 acc
  | p >= r    = g ps [] (r : rs) (x - 1) 0 (acc + p)
  | otherwise = g (p : ps) [] rs (x - 1) 0 (acc + r)

g (p : ps) (q : qs) (r : rs) x y acc
  | p == maximum [p, q, r] = g ps (q : qs) (r : rs) (x - 1) y (acc + p)
  | q == maximum [p, q, r] = g (p : ps) qs (r : rs) x (y - 1) (acc + q)
  | r == maximum [p, q, r] && last ps > last qs = g (p : ps)
                                                    (q : qs)
                                                    rs
                                                    x
                                                    (y - 1)
                                                    (acc + r)
  | otherwise = g (p : ps) (q : qs) rs (x - 1) y (acc + r)