ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

USU Championship 2008

About     Problems     Submit solution     Judge status     Standings
Contest is over

B. Trip

Time limit: 1.0 second
Memory limit: 64 MB
Son-of-Sam had to go a long way from Yekaterinozavodsk to the transoceanic city Vas Legas, where an international contest in bricklaying was to be held. The airport of Yekaterinozavodsk was numbered 1, and the airport of Vas Legas was numbered N. Long-distance flights had been recognized as dangerous, and there were only flights between cities whose numbers differed by 1. That meant that Son-of-Sam had to make N − 2 changes. He had downloaded schedules of all flights and determined which flights he would take. However, when he came to the airport of Yekaterinozavodsk exactly at midnight, he learned a disappointing news: because of meteorological, economic, and geopolitical reasons, all flights would leave the ith airport Di minutes later than the time given in the schedule. Son-of-Sam had to know in what time he would be in Vas Legas, only to see that he was late for the contest because of his bad luck.


The first line contains the number of cities N in Son-of-Sam's route (2 ≤ N ≤ 100). Then the airports with numbers 1, 2, …, N − 1 are described successively. The first line of the description of the ith airport contains integers Qi, Di, and Ti separated with a space; they are the number of flights leaving every day from the airport i to the airport i + 1, the delay in minutes in the departures from the ith airport, and the time in minutes of flying from the airport i to the airport i + 1 (1 ≤ Qi ≤ 10; 0 ≤ Di, Ti < 1440). In the second line of the description of an airport, there are departure times, separated with a space, for all Qi flights in the format HH:MM (0 ≤ HH ≤ 23; 0 ≤ MM ≤ 59). The flight schedule is the same every day, and Son-of-Sam can change flights instantly.


Output time in minutes in which Son-of-Sam will be in Vas Legas.


2 60 1200
00:00 01:00
2 0 300
20:30 21:30
1 0 600
1 60 60
Problem Author: Alex Samsonov
Problem Source: XIII Open USU Championship
To submit the solution for this problem go to the Problem set: 1629. Trip