import           Data.List

main :: IO ()
main = do
    [n, m, k] <- map read . words <$> getLine
    an <- map read . words <$> getLine
    bm <- map read . words <$> getLine
    print $ solve m k an bm

solve :: Int ->  Int -> [Int] -> [Int] -> Int
solve m k an bm = i + j
    where
      ((_, i), (_, j)) = maximumBy (\ ((a, _), (b, _)) ((c, _), (d, _)) -> (a + b) `compare` (c + d)) $ f 0 0 ans bmr
          where
            ans = takeWhile (<=k) $ scanl' (+) 0 an
            bmr = dropWhile (>k) . reverse $ scanl' (+) 0 bm
            f _ _ [] _ = []
            f i' j' (a:an') [] = ((a, i'), (0, 0)) : f (i' + 1) j' an' []
            f i' j' (a:an') bm' = ((a, i'), (head ys, m' - jj)) : f (i' + 1) (j' + jj) an' ys
              where
                jj = j' + length xs
                m' = length bmr - 1
                (xs, ys) = break (<=k - a) bm'
