import Control.Monad import Data.List calc' :: [(Int,Int)] -> Int -> Int -> Int calc' _ p acc | p == 0 = acc calc' _ p acc | p < 0 = acc-1 calc' ((_,w):rest) p acc = calc' rest (p-w) (acc+1) calc :: [Int] -> [Int] -> Int -> Int calc d c p = let pairs = sort $ zip d c in calc' pairs p 0 main = do line <- getLine let d = map read $ words line line <- getLine let c = map read $ words line line <- getLine let p = read line print $ calc d c p