
let () = Scanf.scanf "%d %d %d\n" @@ fun n m k ->
  let acum = Array.make (n+1) 0 in
  let bcum = Array.make (m+1) 0 in
  let ok = ref 0 in
  let ng = ref (n+m+1) in
  let check x =
    let ids = List.init (n+1) Fun.id in
    let predicate i = x-m <= i && i <= x && acum.(i) + bcum.(x-i) <= k in
    List.exists predicate ids in
  for i = 1 to n do
    if i < n
    then Scanf.scanf " %d" @@ fun a -> acum.(i) <- acum.(i-1) + a
    else Scanf.scanf " %d\n" @@ fun a -> acum.(i) <- acum.(i-1) + a
  done;
  for i = 1 to m do
    if i < m
    then Scanf.scanf " %d" @@ fun b -> bcum.(i) <- bcum.(i-1) + b
    else Scanf.scanf " %d\n" @@ fun b -> bcum.(i) <- bcum.(i-1) + b
  done;
  while !ng - !ok > 1 do
    let mid = (!ok + !ng) / 2 in
    if check mid
    then ok := mid
    else ng := mid
  done;
  Printf.printf "%d\n" !ok