Log Books
Time limit1sMemory limit128 MB
For each log book, sum total and night driving minutes and check the 50-hour, 10-hour, and 2-hour per-session limits, printing PASS or NON.
- Level
Medium4 of 10
- Topics
- Implementation, Simulation, Math, Brute force
- Solved
- No attempts yet
Problem
A learner driver must complete 50 hours of supervised driving, and at least 10 of those hours must be night driving. Every learner keeps a log book of their supervised driving; each entry records the start time and finish time of a single driving session.
An inspector must check each log book and verify two things: that the recorded driving times meet the requirements, and that no single driving session is longer than 2 hours.
Night driving is any time before sunrise or after sunset. For one session, if at least half of its length falls during the night, then the whole session counts as night driving. For example, a session from 04:50 to 06:10 on a day when sunrise is at 05:30 counts as night driving (40 of its 80 minutes are before sunrise, which is exactly half).
Write a program that reads a log book and decides whether all requirements are met without any session exceeding the 2-hour limit.
Input
The input contains several log books. Each log book begins with a line containing a single integer , the number of entries in that log book (). Each of the next lines describes one driving session with four times, separated by single spaces, in this order: sunrise, sunset, session start, and session finish. The start time is strictly earlier than the finish time. Every time is between 00:00 (midnight) and 23:59 inclusive, written as HH:MM. A line containing a single 0 ends the input and is not a log book.
Output
For each log book, print PASS on its own line if all requirements are met: the total driving time is at least 50 hours, the night driving time is at least 10 hours, and no single session exceeds 2 hours. Otherwise print NON.