Anton and the School Schedule
Time limit1sMemory limit512 MB
Given a Monday-to-Friday lesson grid and a sleep-deficit threshold k, find the week and day when Anton first oversleeps his first lesson, or report -1.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Statement
Anton goes to school from Monday to Friday. Lessons last for minutes and breaks last for minutes. The first lesson starts at 7 a.m. and the last lesson finishes at 3:45 p.m. Each lesson starts at the beginning of an hour.
Anton wants to stay healthy, so he wants to sleep for hours every day. He does not always manage this, because lessons can start at 7 a.m. To average 8 hours of sleep a day, he can sleep more on Saturday and Sunday, when he does not go to school. Anton cannot sleep more than hours a day, because otherwise he feels that he has slept too much and the rest of the day feels bad. Anton gets up at least one hour before the first lesson to eat breakfast and get to school. Anton falls asleep at midnight every day.
Anton wants to attend all of his lessons. However, if on a day when he has to get up for school he has a lack of sleep of at least hours, he will oversleep his first lesson. Anton starts going to school on Monday. At first he has no lack of sleep, because he rested during the summer.
Help Anton find the day when he will oversleep his first lesson.
Input
The first line contains , the number of lack of sleep hours that Anton needs to oversleep his first lesson. ()
The next five lines each contain 9 characters, each 0 or 1, describing Anton's school schedule from Monday to Friday. On Saturday and Sunday Anton does not go to school. If on day Anton has lesson , then the -th character of the -th row is 1, otherwise it is 0.
Output
If Anton never has a lack of sleep and never oversleeps his lessons, output -1. Otherwise, output two integers: the week number and the day on which Anton will oversleep his first lesson.
Hint
Every day Anton's lessons run from 7:00 a.m. to 1:45 p.m., so every day he gets up at 6 a.m. and accumulates 2 hours of lack of sleep. By the weekend Anton has accumulated 10 hours of lack of sleep, but he can make up 4 of them by sleeping 10 hours on Saturday and Sunday. Starting the second week with 6 hours of lack of sleep, Anton oversleeps his first lesson on Wednesday.