let split_string ?(pattern="") = Str.split @@ Str.regexp pattern

let (n, m, k) = Scanf.sscanf (read_line ()) "%d %d %d" @@ fun n m k -> (n, m, k)
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> Array.of_list
let b = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> Array.of_list


let sa = Array.make (n + 1) 0
let sb = Array.make (m + 1) 0

let rec solve i = function
  | 0 -> (i, 0)
  | j -> if sa.(i) + sb.(j) > k then solve i (j - 1) else (i + j, j)

let () =
  for i = 1 to n do sa.(i) <- sa.(i - 1) + a.(i - 1) done;
  for i = 1 to m do sb.(i) <- sb.(i - 1) + b.(i - 1) done;
  Printf.printf "%d\n" @@ fst 
    @@ Array.fold_left (fun (m, j) i -> 
      if sa.(i) > k then (m, j)
      else let (nm, nj) = solve i j in (max m nm, nj)
    ) (0, m) 
    @@ Array.init (n + 1) @@ fun i -> i