fork download
  1. import Control.Monad
  2. import Data.List
  3.  
  4. calc' :: [(Int,Int)] -> Int -> Int -> Int
  5. calc' _ p acc | p == 0 = acc
  6. calc' _ p acc | p < 0 = acc-1
  7. calc' ((_,w):rest) p acc = calc' rest (p-w) (acc+1)
  8.  
  9. calc :: [Int] -> [Int] -> Int -> Int
  10. calc d c p =
  11. let pairs = sort $ zip d c
  12. in
  13. calc' pairs p 0
  14.  
  15. main = do
  16. line <- getLine
  17. let d = map read $ words line
  18. line <- getLine
  19. let c = map read $ words line
  20. line <- getLine
  21. let p = read line
  22. print $ calc d c p
  23.  
Success #stdin #stdout 0.01s 5584KB
stdin
2 5 1 3
2 3 3 4
6
stdout
2