eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Rabbit Jumping

Rabbit Jumping

There are \textbf{K} rabbits playing on rocks floating in a river. They got tired of playing on the rocks on which they are standing currently, and they decided to move to other rocks. This seemed an easy task initially, but there are so many constraints that they got totally confused. First of all, by one leap, they can only move to a rock within \textbf{R} meters from the current rock. Also, they can never leap over rocks. That is, when they leap in some direction, they should land on the nearest rock in that direction. Furthermore, since they always want to show off that they are courageous, they will never leap to rocks downriver. Finally, since they never want to admit they have been defeated, they never land on a rock if the rock is already visited by other rabbits. In this situation, is it possible for them to move to their destination rocks? If possible, please minimize the sum of their moving distance. \InputFile The first line contains two integers \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{100}), \textbf{K} (\textbf{1} ≤ \textbf{K} ≤ \textbf{3}) and a real number \textbf{R} (\textbf{0} ≤ \textbf{R} ≤ \textbf{10}), which denote the number of rocks, the number of rabbits, and the maximum distance a rabbit can leap, respectively. The second line contains \textbf{K} numbers \textbf{s_1}, ..., \textbf{s_K} where \textbf{s_i} denote the rock where the \textbf{i}^th rabbit is standing. Similarly, the third line contains \textbf{K} numbers \textbf{t}_1, ..., \textbf{t_K} where \textbf{t_i} denote the destination rock for the \textbf{i}^th rabbit. \textbf{s_1}, ..., \textbf{s_K} are distinct, and \textbf{t}_1, ..., \textbf{t_K} are distinct. A destination rock of a rabbit is always different from the rock heshe is standing currently. Then the following \textbf{N} lines describe the positions of the rocks. The \textbf{i}^th line in this block contains two integers \textbf{x_i} and \textbf{y_i} (\textbf{0} ≤ \textbf{x_i}, \textbf{y_i} ≤ \textbf{10000}), which indicate the coordinates of the \textbf{i}^th rock. The river flows along \textbf{Y}-axis, toward the direction where \textbf{Y}-coordinate decreases. No pair of rocks has identical coordinates. You may assume that the answer do not change even if you increase \textbf{R} by up to \textbf{10^\{-5\}}. \OutputFile If all the rabbits can move to their destination rocks, print the minimum total distance they need to leap. If not, print "\textbf{-1}" (without quotes). Your answer may contain at most \textbf{10^\{-6\}} of absolute error.
Лимит времени 5 секунд
Лимит использования памяти 64 MiB
Входные данные #1
6 3 1.0
1 2 3
4 5 6
0 0
1 0
2 0
0 1
1 1
2 1
Выходные данные #1
3
Источник The 2011 35th Annual ACM Programming Contest Winter Camp