let n, m, k = Scanf.scanf "%d %d %d" (fun n m k -> n, m, k)
let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun i-> i))
let b = Array.init m (fun _ -> Scanf.scanf " %d" (fun i-> i))

let rec f i a c n =
  if i < n then (
    c.(i + 1) <- c.(i) + a.(i);
    f (i + 1) a c n
  )

let c = Array.make (n + 1) 0
let d = Array.make (m + 1) 0

let rec g ans i j =
  if i = n + 1 || k < c.(i) then ans
  else
    let rec h i j =
      if k < c.(i) + d.(j) then h i (j - 1)
      else j in
    let j = h i j in
    g (max ans (i + j)) (i + 1) j

let () =
  f 0 a c n;
  f 0 b d m;
  let ans = g 0 0 m in
  Printf.printf "%d\n" ans
