Roller coaster velociraptor

You are going to get on a roller coaster when you realize that a
velociraptor is coming straigh at you. Fortunately, you have a way to
escape: the roller coaster. You know that the velociraptor can follow
you through the rail, but he will not fit in the tunnel of the roller
coaster. You start to push the car in the platform while the
velociraptor is chasing you. For obvious reasons you want to get on the
car as soon as possible: you want to obtain the speed enough to reach
the tunnel and get rid of the velociraptor, but you do not want to push
more than the strictly needed in case it catches you in the platform.

You know all the rises and way down that the roller coaster has.
Moreover, you know that for each metre in vertical that goes up, the car
loses a speed of K kilometres per hour, while for each metre in vertical
that goes down, recovers the same lost speed of K kilometres per hour
(the laws of physics are not fulfilled in theme parks; if not, it would
not have any sense paying so much for the ticket). You also know that
there is not any friction with the rail, and that is possible that the
car has speed 0 during some moment of the route (you can gather momentum
and car would continue) but at any moment it can have negative speed.

Input

The first line of the test data contains the number of cases to solve.
Each case starts with 3 integers N, X and K in a line, where N is the
number of stretches of the roller coaster, X is the coordinate x of the
point where the tunnel is, and K is the speed in kilometres per hour
that is lost (respectively, is won) for each metre gone up
(respectively, gone down) in vertical. The following N + 1 lines contain
N + 1 pairs of coordinates (x_(i), y_(i)), separated by a space, that
describe the extremes of the N straight stretches that the attraction is
composed of. It is fulfilled that (x₁, y₁) is always (0, 0), and that
the x_(i) are stricly increasing that is, x_(i) < x_(i + 1). Moreover,
the tunnel always is in the beginning of a stretch of the roller
coaster, that is, exists a point x_(i) with 1 < i ≤ N such that
x_(i) = X.

Output

For each case, your program must print in a line the minimal speed in
kilometres per hour which you have to leave the platform with to reach
the beginning of the tunnel, assuring that during the whole route the
speed of the car is greater or equal than 0.

Scoring

- TestA:   Tests with no more than 20 cases where N ≤ 15 and X ≤ 1000.

- TestB:   Tests with no more than 20 cases where N ≤ 25000 and X ≤ 10⁶.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:58:34.538Z

© Jutge.org, 2006–2026.
https://jutge.org
