Advanced Causal Measurements (ACM)
Time limit1sMemory limit128 MB
Given n observed events and m causes, place the m causes so all events are causally reachable and the earliest cause time is maximized.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Geometry, Sorting
- Solved
- No attempts yet
Problem
Causality is a very important concept in theoretical physics. The basic elements in a discussion of causality are events. An event is described by its time of occurrence and its location , and we write . For our concerns, all events happen in a one-dimensional geometric space, so a location is a single real number (a coordinate on the -axis). Theoretical physicists like to set the speed of light to , so that time and space share the same units.
One event is a possible cause of a second event if a signal emitted at could reach . A signal cannot travel faster than light, so this condition can be written as
Thus an event at could cause events at , , and , but could not have caused events at or . Note that a single event can cause several others.

Scientists have observed several unusual events in this one-dimensional universe. From current theory they know how many causes were responsible for these observations, but they know nothing about the times and locations of those causes. There are exactly causes, and every observed event must have at least one of these causes as a possible cause.
Write a program that determines the latest time at which the earliest cause could have occurred — that is, the largest integer such that, no matter how the causes are placed, at least one cause occurs at time or earlier. Equivalently, place the causes so that they are possible causes of all observed events while making the earliest cause time as large as possible, and report that time.
All observed events have integer coordinates with .
Input
The first line contains the number of test cases. Each test case begins with a line containing the number of events and the number of causes (). The next lines each contain the coordinates and of one event.
Output
For each test case, print a single line Case k: a, where is the test case number (starting from ) and is the latest time at which the earliest cause could have occurred. This value is always an integer, because our time units are not divisible.