Going to School
InterviewTime limit1sMemory limit1024 MB
Given N buses with departure time S and travel time T, find the latest departure among buses where S + T is at most X, or print -1 if none qualify.
- Level
Easy1 of 10
- Topics
- Implementation, Array
- Solved
- No attempts yet
Problem
Jeongol must reach school within minutes to avoid being late for class. To get there, he must choose one of the buses that stop at the bus stop and board it.
Jeongol wants to board as late as possible. He looked up information on all buses. For each bus, he found out how many minutes from now it leaves the bus stop and how many minutes it takes to get from the bus stop to school. He has not yet decided which bus to take.
Among the buses that get him to school on time, find the time until the latest-departing bus leaves. It is possible that no bus gets him to school on time.
Input
The first line contains and , separated by a single space.
Each of the next lines contains and , separated by a single space. is the number of minutes from now until the bus leaves the bus stop, and is the number of minutes the bus takes to get from the bus stop to school.
Output
If Jeongol cannot reach school within minutes, print .
Otherwise, print the number of minutes until the latest-departing bus that gets him to school on time leaves the bus stop.
Constraints
All given numbers are integers.
- For each bus, is the number of minutes until it leaves the bus stop, and is the number of minutes it takes to get from the bus stop to school.