
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE BangPatterns #-}

module Main where

import Debug.Trace
import Data.List
--import qualified Data.Set.Strict as Set
--import qualified Data.Map.Strict as Map

main :: IO ()
main = do
  [_, _, k] <- map read . words <$> getLine
  a <- map read . words <$> getLine
  b <- map read . words <$> getLine
  --a `traceShow`
  print $ solve k a b

solve :: Int -> [Int] -> [Int] -> Int
solve k a b
  | null a'' = 0 
  | otherwise = maximum $ map (\a''' -> search k a''' b'') a''
  where
    a' = zip (takeWhile (<= k) . tail $ scanl (+) 0 a) [1..]
    b' = zip (takeWhile (<= k) . tail $ scanl (+) 0 b) [1..]
    (a'', b'') = if null a' then (b', a') else (a', reverse b')


search :: Int -> (Int, Int) -> [(Int, Int)] -> Int
search k (a, ai) bl = case find (\(b, bi) -> k >= a + b) bl of Just (b, bi) -> ai + bi
                                                               Nothing -> ai
