main = do
    [n,m,k] <- map read . words <$> getLine :: IO [Int]
    as <- zip [0..] . takeWhile (<=k) . scanl (+) 0 . map read . words <$> getLine
    bs <- zip [0..] . takeWhile (<=k) . scanl (+) 0 . map read . words <$> getLine
    print $ maximum $ solve as (reverse bs) k

solve [] [] km = []
solve [] _ km = []
solve _ [] km = []
solve (a:as) (b:bs) km | (sum . map snd) [a,b] <= km = [(sum . map fst) [a,b]] ++ solve as (b:bs) km
                       | otherwise = solve (a:as) bs km
