import Data.List

ans' _ [] _ = []
ans' n (l:ls) c =
  let a = take l $ sortBy (\[_,v0] [_,v1] -> compare v1 v0) $ filter (\[i,_] -> i == n) c
  in
    a ++ (ans' (n+1) ls c)

ans m l c =
  let a = ans' 1 l c
      t = take m $ sortBy (\[_,v0] [_,v1] -> compare v1 v0) a
      s = sum $ map (\[_,v] -> v) t
  in
    s

main = do
  [_,m,_] <- fmap (map read . words) getLine :: IO [Int]
  l <- fmap (map read . words) getLine :: IO [Int]
  c <- fmap (map (map read) . map words . lines) getContents :: IO [[Int]]
  let o = ans m l c
  print o

