
{-# 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 = s `traceShow` (maximum $ s)
solve k a b = maximum s
  where
    a' = zip (takeWhile (<= k) $ scanl (+) 0 a) [0..]
    b' = zip (takeWhile (<= k) $ scanl (+) 0 b) [0..]
    (a'', b'') = if null a' then (b', a') else (a', b')
    s = build k a'' (reverse b'')

build :: Int -> [(Int, Int)] -> [(Int, Int)] -> [Int]
build k [] _  = []
build k al [] = map snd al
--build k al@((a, ai):as) bl@((b, bi):bs) = (al, bl) `traceShow` if a + b <= k then (ai + bi) : build k as bl else build k al bs
build k al@((a, ai):as) bl@((b, bi):bs) = if a + b <= k then (ai + bi) : build k as bl else build k al bs
