Oscar is the captain of his very own spaceship, which he has endearingly named Oscarella.
Oscar will be embarking on missions to collect gems from planet Globgalab. On each mission he will attempt to get gems (this quantity will vary between missions). To collect a gem, he must fly his ship directly over the gem and beam it up. Oscar wants to collect all the gems, but he also wants to minimize the distance he moves so that Oscarella can remain in pristine condition.
However, there is one other issue. Each gem has a weight of . The ship, Oscarella, has a certain power level that dictates what gem it can pick up. Specifically, if Oscarella has a power level of , it can only pick up a gem that weighs no more than pounds.
(Note, the function returns the greatest integer less than or equal to x.)
To aid him on his mission, Oscar can use the gems he has picked up to increase Oscarella's power level further. A gem with weight will increase Oscarella's power level by . Oscar and his spaceship will start at , can you help him find the minimum distance he must travel to get all gems?
Input Specification
The first line contains a single integer , the number of missions per test case,
The inputs for the missions follow.
The first line of each mission input contains two positive integers, and , ,
Each of the next lines each contain three integers, , and , representing the (, ) position and weight of the gem, in pounds. ,
No two gems will be at the same location.
Output Specification
For each input case, on a line by itself, output -1.0
if there is no way for Oscarella to beam up all the gems or the shortest distance it needs to travel to beam up all the gems otherwise.
Note, for all cases where Oscarella can beam up all the gems, any answer within an absolute or relative error of will be accepted.
Subtasks
Subtask 1 [60%]
Subtask 2 [40%]
No additional constraints.
Sample Input
2
100 3
20 0 21
30 0 5
40 0 10
125 4
1 1 30
-1 1 4
-1 -1 6
1 -1 5
Sample Output
60.0
-1.0
Comments