## TLE '17 Contest 7 P2 - Airport Hopping

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
Joey flying in a plane.

Joey is going to take a vacation in Mexico. He wants to go from Toronto Pearson International Airport YYZ to Cancun International Airport CUN. During the way, he may make multiple stops.

During his trip, he will pass through airports, starting at YYZ labelled and ending at CUN labelled . Joey starts at YYZ on day hour . There are hours in day.

In total, there are regularly scheduled flights. Each flight can be described by 3 integers , meaning that the flight starts from airport and goes to airport , starting at hour every day, and takes hours to fly to the next airport. Due to slow airport security lines, Joey must wait for minutes before getting on a flight, and minutes after getting off a flight.

In Mexico, there is a celebration of the fire god every hour of the day. Given that he travels optimally, what is time of the earliest show that Joey can watch?

#### Input Specification

The first line will contain , .

The next lines will contain , , .

It is guaranteed that it is always possible to fly to Mexico.

#### Output Specification

Print a single line: Day D Hour H, indicating the time of the earliest show that Joey can watch.

2 1
1 1 1

Day 0 Hour 3

#### Sample Explanation 1

Joey arrives at airport at 2:00, and gets off at 2:20.

3 3
1 2 10
1 1 48
2 12 1

Day 1 Hour 14

#### Sample Explanation 2

Joey should not take the plane that takes hours as that is too slow.

Joey should arrive at airport at Day Hour using the hour plane, but Joey misses the next flight because he must wait for minutes to pass airport security after getting off the flight, and another minutes to pass security before getting on his next flight.

He gets on the airplane to depart airport on Day Hour and arrives at Mexico at Day Hour . Finally gets off the plane at 13:20 and visits the show on Day Hour .