let () = Scanf.scanf "%d %d\n" @@ fun w h ->
  begin
    Array.to_list (Array.init w (fun i ->
      Scanf.scanf "%d\n" (fun p -> (p, `Col)))) @
    Array.to_list (Array.init h (fun i ->
      Scanf.scanf "%d\n" (fun q -> (q, `Row))))
  end
  |> List.sort (fun (p, _) (q, _) -> compare p q)
  |> List.fold_left (fun (cost, (row, col)) -> function
    | (p, `Col) -> (cost + p * (h + 1 - row), (row, col + 1))
    | (q, `Row) -> (cost + q * (w + 1 - col), (row + 1, col))) (0, (0, 0))
  |> fst
  |> Printf.printf "%d\n"


