import Control.Monad
import Data.List
import Data.Ord

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 = sort' $ concat $ sortOn Down (map reverse reads)
  print $ foldl' (+) 0 (func xs cs)

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

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