import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m,k] <- getIntList
    as <- getIntList
    bs <- getIntList
    let sa = takeWhile (<=k) $ scanl (+) 0 as
        sb = takeWhile (<=k) $ scanl (+) 0 bs
    let ansa = maximum $ solve k (length sa - 1) (reverse sa) sb
        ansb = maximum $ solve k (length sb - 1) (reverse sb) sa
    print $ max ansa ansb

solve k l [] _ = [0]
solve k l _ [] = [0]
solve k l (a:sa) (b:sb)
    | a + b <= k = l : solve k (l+1) (a:sa) sb
    | a + b > k = solve k (l-1) sa (b:sb)                    