#C6269. Baton Relay Challenge
Baton Relay Challenge
Baton Relay Challenge
You are tasked with determining the earliest time at which the last runner receives the baton in a relay race.
The race consists of n runners. Between runners, there is a baton hand-off process that has specific timing constraints. For each baton pass, a time interval \( [l_i, u_i] \) is given which represents the minimum and maximum allowed time to pass the baton. In an optimal scenario, the baton is passed exactly after the minimum required time \( l_i \) in order to finish the relay as soon as possible.
Note: The total number of baton passes is \( n-1 \) because the baton is passed from the first runner to the second, and so on until the last runner receives it.
Your task is to compute the earliest possible time for the last runner to receive the baton, which is the sum of the minimum times for each baton pass.
inputFormat
The input is given from standard input (stdin) in the following format:
n l1 u1 l2 u2 ... (n-1 lines in total)
Here, n
is the number of runners, and for each baton pass, \( l_i \) and \( u_i \) represent the minimum and maximum passing times, respectively.
outputFormat
Output a single integer to standard output (stdout) representing the earliest time at which the last runner receives the baton.
## sample3
2 5
3 10
5
</p>