526. Running Hero
Time limit per test: 0.5
second(s)
Memory limit: 262144
kilobytes
input: standard
output: standard
Aladdin is running through a long cave. He is very fast and can move with a speed of at most
v meters per second, but falling stones prevent him from running always at maximum speed.
Now imagine a 2dimensional world with Aladdin being a point moving in the positive or negative direction of the
Xaxis, and stones, falling down on the Al's head, being segments parallel to the
Xaxis. Another point in this world is princess Jasmin. She is waiting for Al at the point (
G, 0). Aladdin starts his way at the point (0, 0). A stone kills Aladdin if he is located strictly between the endpoints of the stone when the stone reaches the ground. As Jasmin is in a fortified trench, the stones can't hurt her even if they fall down on her head.
You are given Aladdin's maximum speed, Jasmin's position and information about times and places of falling stones. Your task is to find the whether it is possible for Aladdin to to reach Jasmin. If it's possible, you also have to find the sequence of actions which gets Aladdin to Jasmin in the minimum amount of time possible.
Input
The first line of the input contains three integers
v,
G and
n (1 ≤
v ≤ 10
^{5}, 0 < G ≤ 10
^{5}, 0 ≤
n ≤ 3000) — Aladdin's maximum speed, Jasmin's
xcoordinate and the number of stones. Each of the following
n lines contains three integers
x_{1,i},
x_{2,i} and
t_{i} (10
^{5} ≤
x_{1,i} ≤
x_{2,i} ≤ 10
^{5}, 1 ≤
t_{i} ≤ 10
^{5}) — left and right endpoints of the
ith stone, and time when the
ith stone reaches the ground.
Output
If there is no solution, the output should contain a single integer 1.
Otherwise the first line of the output should contain one integer
k — the number of instructions for Aladdin. Each of the following
k lines should contain a pair of spaceseparated real numbers — speed
w and time
t. A pair (
w,
t) means that Aladdin should run
t seconds at speed
w. Speed
w should be negative, if Aladdin should move in the negative direction of the
Xaxis and nonnegative otherwise. Value
t should always be positive. The value
w=0 means that Aladdin doesn't move for time
t.
If there are many solutions, you may output any of them. All real values should be printed with at least 9 digits after the decimal point. The number of instructions
k in your output must not exceed 10000.
Example(s)
sample input

sample output

5 35 2 5 6 1 5 35 9

2 5.000000000000000000 1.000000000000000000 5.000000000000000000 8.000000000000000000

Note
Aladdin can change his speed instantly. If some stone falls down on Al's head at the moment of or after his meeting with Jasmin, it can't prevent the two from kissing each other and can't change anything.