Internet
InterviewTime limit1sMemory limit1024 MB
Given measurements with connection states, where the first and last show a connection, find the longest possible time the connection could have been down.
- Level
Medium4 of 10
- Topics
- Greedy, Implementation, Intervals
- Solved
- No attempts yet
Problem
Tomas's internet connection is often unstable, and sometimes it drops out entirely. Tomas wants to know how long he might have to wait for a dropped connection to come back, so every now and then he checks whether he has an internet connection at that moment and writes it down.
Tomas remembers that he had a connection during both the first and the last measurement.
Help Tomas find the longest time he could possibly have gone without internet.
Input
The first line contains a single integer , the number of measurements Tomas made.
Each of the next lines contains two integers and . is the time at which Tomas took the -th measurement, and is its result: is if he had an internet connection at that moment, or if he did not.
The measurements are given in increasing order of .
Output
Print a single integer: the longest time interval during which Tomas could have been without internet.