Wankan

Borrowing Books in CF

Sep 10th, 2020 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. single_input :: IO ->> Int
  3. Empty => Int IO.raw_input ""
  4.  
  5. double_input :: IO ->> (Int, Int)
  6. Empty ~> {
  7.     Empty => IO.raw_input "",
  8.     raw => String.split raw " ",
  9.     [a, b, ...c] => (Int a, Int b),
  10. }
  11.  
  12. output_val :: Bool ->> IO
  13. True => IO.log <- 1
  14. False => IO.log <- 0
  15.  
  16. borrow :: [Int], Int, Int ->> [Int]
  17. books, idx, dur => books[idx] = dur
  18.  
  19. day_passing :: [Int] ->> [Int]
  20. books => @ (books''0 - 1)
  21.  
  22. available :: [Int], Int ->> Maybe Bool
  23. book, idx | idx < 0 => Nothing
  24. book, idx | idx > length book => Nothing
  25. book, idx => book[idx] <= 0
  26.  
  27. do:
  28.     nbBooks, nbDays = double_input ()
  29.     books = fill [0..nbBooks] 0
  30.     for day in [0..nbDays]:
  31.         for c in [0..single_input ()]:
  32.             idx, dur = double_input ()
  33.             avail = available books idx
  34.             IO.log <- output_val avail
  35.             if avail:
  36.                 borrow books idx dur
  37.         books = day_passing books
  38.            
  39.  
Add Comment
Please, Sign In to add comment