let [|n;m;k|] = stdin.ReadLine().Split() |> Array.map int
let a = stdin.ReadLine().Split() |> Array.map int64
let b = stdin.ReadLine().Split() |> Array.map int64

let suma =
    a
    |> Array.scan (+) 0L

let mutable sumb =
    b
    |> Array.scan (+) 0L

let rec f x j =
    if sumb.[j]<=x then j
    else f x (j-1)

let rec g i j v =
    if i = n+1 then v
    elif suma.[i] > int64(k) then v
    else
        let ib = f (int64(k)-suma.[i]) j
        if ib+i > v then g (i+1) ib (ib+i)
        else g (i+1) ib v

g 0 m 0 |> stdout.WriteLine