import Data.List

main :: IO ()
main = do
    [_, _, k] <- map read . words <$> getLine
    as <- map read . words <$> getLine
    bs <- map read . words <$> getLine
    let as' = takeWhile (\x -> snd x <= k) [(n, sum (take n as)) | n <- [0..length as]]
        bs' = [fst $ last $ takeWhile (\(b, y) -> y + sum (take b bs) <= k) [(m, x) | m <- [0..length bs]] | (a, x) <- as']
        tmp = zipWith (\(a, x) b -> a + b) as' bs'
        res = maximum tmp
    putStrLn $ show res