From the logged safe and broken drops, compute the lowest floor that could break and the highest floor that could stay safe.
Easy2IntervalsImplementationInterviewNo attempts yetTime limit2sMemory limit256 MBYou have two eggs and a building with k floors, and you want to find the highest floor from which an egg can be dropped without breaking. That is the classic riddle.
Someone already ran the experiment and left a log behind. The log lists floor numbers together with the result of dropping an egg from each of those floors. From the log alone, compute two numbers: the lowest floor from which the egg could break, and the highest floor from which the egg might not break.
An egg dropped from floor 1 does not break, and an egg dropped from floor k always breaks. The log is consistent with itself: if an egg did not break on floor x, it does not break on any lower floor, and if an egg broke on floor y, it breaks on every higher floor.
The first line contains two integers n and k separated by one space (1≤n≤100, 3≤k≤100), the number of logged drops and the number of floors of the building. Each of the next n lines contains a floor number and the result of that drop, separated by one space. The floor number is between 1 and k, and the result is either SAFE or BROKEN.
Print two integers separated by one space on a single line. The first integer is the lowest floor from which the egg could break while staying consistent with the log. The second integer is the highest floor from which the egg might not break.