{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Data.List
import Control.Monad

readLine :: Read a => IO [a]
readLine = map read . words <$> getLine

calc :: [Int] -> [Int] -> Int -> Int -> Int -> Int
calc ca cb i j k
    | null ca = 0
    | null cb = 0
    | head ca > k = 0
    | head ca + head cb > k = calc ca (tail cb) i (j-1) k
    | otherwise = maximum [i+j, calc (tail ca) cb (i+1) j k]

main :: IO ()
main = do
    [n, m, k] <- readLine
    a <- readLine
    b <- readLine
    let ca = scanl (+) 0 a
    let cb = scanl (+) 0 b
    print $ calc ca (reverse cb) 0 m k