Cooking Water
InterviewTime limit1sMemory limit512 MB
Given N intervals of time Edward did not watch a pot, decide whether some single boil time is possible, meaning it lies inside every unwatched interval.
- Level
Medium4 of 10
- Topics
- Intervals, Implementation, Greedy
- Solved
- No attempts yet
Problem
"A watched pot never boils," as the saying goes. Chef Edward has been cooking for ages, and empirically the saying seems to hold in his kitchen. He has yet to see a pot actually start boiling. His wife Gunilla is a bit suspicious of Edward's claim. She knows how he often loses focus after a little while, and thinks it is very likely that Edward gets tired of watching after about the same period of time starting when he puts the pot on the stove.
Being scientifically minded, Gunilla quickly designed an experiment that could help Edward gain more insight into the boiling of pots. Every time during the last week that Edward boiled a pot of water, he wrote down the intervals of time when he was not watching the pot. Now he has a large log of these intervals, and wonders whether Gunilla is right (that is, it may be the case that Edward just happened to look away every time the pot started boiling), or if his hypothesis is correct.
Given this data, is it possible that the pot actually starts boiling after the same amount of time, every time?
Input
The first line of the input contains an integer , the number of times Edward boiled water in the last week. Then descriptions of a boiling follow. Each description contains two numbers . This means that Edward looked away during seconds (that is, from the start of second to the end of second ), and that Edward first saw the pot boiling once he looked back.
Output
If it is impossible that all the pots actually started boiling at the same point in time, output edward is right. Otherwise, output gunilla has a point.