import Control.Monad
import Data.List

main = do
  [n, m] <- map read . words <$> getLine
  cards <- map read . words <$> getLine
  reads <- replicateM m $ map read . words <$> getLine
  let cs = sort cards
  let xs = reverse $ sort $ sort' $ concat reads
  print $ sum $ func xs cs

sort' :: [Int] -> [Int]
sort' [] = []
sort' (a:b:xs) = replicate a b ++ sort' xs

func :: [Int] -> [Int] -> [Int]
func xs cs = zipWith max (xs ++ repeat 0) cs
