Why Did the Cow Cross the Road 3
Time limit2sMemory limit512 MB
Given each cow's arrival and inspection time, find the earliest time all cows finish entering when inspected one at a time in arrival order.
- Level
Easy3 of 10
- Topics
- Sorting, Simulation
- Solved
- No attempts yet
Problem
Fed up with cows from the neighboring farms crossing the road at random, John makes a drastic decision: he builds a very large fence around his farm. With it in place, cows from nearby farms can hardly ever get in. The cows around him are furious. They can no longer visit their friends, and this year they cannot even attend the International Milking Olympiad they enter every year.
A few cows from the neighboring farms are still allowed to visit John's farm, but they cannot relax either. The farm has only one gate, and every cow that passes through it must go through a long inspection by a guard. When several cows try to enter at once, the line grows accordingly.
cows have come to visit the farm. The arrival time and the inspection time differ from cow to cow (they can also be equal). Two cows cannot be inspected at the same time. For example, if one cow arrives at second 5 and is inspected for 7 seconds, the next cow, which arrives at second 8, must wait in line until second 12 before its inspection starts.
Find how long it takes until every cow has entered the farm.
Input
The first line contains the number of cows , a positive integer not greater than 100.
Each of the next lines describes one cow with two integers separated by a space: its arrival time and its inspection time. Both values are positive integers not greater than 1,000,000.
Output
Print the earliest time at which every cow has entered the farm. Time is counted from second 0.
Hint
In the example, the first cow arrives at second 2 and enters the farm at second 3. Next, the third cow arrives at second 5 and enters at second 12. Finally, the second cow arrives at second 8, but the third cow is still being inspected, so it waits until second 12 and enters at second 15.