import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let [n,m,k] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  li <- BS.getLine
  let bs = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n m k as bs
  print ans

compute :: Int -> Int -> Int -> [Int] -> [Int] -> Int
compute n m k as bs = maximum $ loop ars 0 0 bs
  where
    ars = reverse $ zip [0..] $ takeWhile (0 <=) $ scanl (-) k as

loop [] _ _ _ = []
loop ((a,r):_) _ bcnt [] = [a+bcnt]
loop arars@((a,r):ars) bsum bcnt bbs@(b:bs)
  | r >= bsum1 = loop arars bsum1 (succ bcnt) bs
  | True       = a+bcnt : loop ars bsum bcnt bbs
  where
    bsum1 = bsum + b