Speed Reading
InterviewTime limit1sMemory limit128 MB
For each cow, simulate reading in bursts of at most T minutes with R-minute rests between, and report the total minutes rounded up to finish N pages.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, Math, Greedy
- Solved
- No attempts yet
Problem
All () cows are taking part in Farmer John's annual reading contest. The contest is to read a single book of () pages as fast as possible while understanding it.
Cow has a reading speed of () pages per minute, a maximum continuous reading time of () minutes, and a minimum rest time of () minutes. The cow reads pages per minute, but she can read for at most minutes at a stretch. Once she stops to rest, she must rest for minutes before she can start reading again.
For each cow, determine the number of minutes (rounded up to the next whole minute) needed to read the entire book.
Input
- Line 1: two space-separated integers and .
- Lines 2 to : line contains three space-separated integers , , and .
Output
- Lines 1 to : line is the number of minutes (rounded up to the next whole minute) that cow needs to read the whole book.
Hint
Reading always happens in whole-minute units. A cow reads in bursts of at most minutes (covering at most pages); if pages still remain afterward she rests minutes and reads again. No rest is needed after the final burst that finishes the book, and a partial last minute still counts as a full minute.
For example, for a 10-page book, a cow that reads 2 pages/min for up to 4 minutes and rests 1 minute reads 8 pages in 4 minutes, rests 1 minute, then reads the last 2 pages in 1 minute, for 6 minutes total.