A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals x i, and its picturesqueness equals b i. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates x i.
Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.
Let’s assume that if the traveler covers distance r j in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.
Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.
The traveler’s path must end in the farthest rest point.
Input
The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path.
Then n lines follow, each line describes one rest point as a pair of integers x i, b i (1 ≤ x i, b i ≤ 106). No two rest points have the same x i, the lines are given in the order of strictly increasing x i.
Output
Print the traveler’s path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing x i. The last printed number must be equal to n.
Examples
input
5 9
10 10
20 10
30 1
31 5
40 10
output
1 2 4 5
Note
In the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as .
Solution:
import java.lang.Double.max import java.lang.Math.abs import java.lang.Math.sqrt private fun readLn() = readLine()!! // string line private fun readInt() = readLn().toInt() // single int private fun readLong() = readLn().toLong() // single long private fun readDouble() = readLn().toDouble() // single double private fun readStrings() = readLn().split(" ") // list of strings private fun readInts() = readStrings().map { it.toInt() } // list of ints private fun readLongs() = readStrings().map { it.toLong() } // list of longs private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles fun main(args: Array<String>) { var (n, l) = readInts() var x = IntArray(n + 1) var b = IntArray(n + 1) for (i in 1..n) { var (foo, bar) = readInts() x[i] = foo b[i] = bar } n++ var low = 0.0 var high = 1e10 var res = ArrayList<Int>() for (it in 0..200) { var mid = (low + high) * 0.5 var dp = DoubleArray(n, { 1e30 }) var pr = IntArray(n) dp[0] = 0.0 for (i in 0..n - 1) { for (j in i + 1..n - 1) { var ft = dp[i] + sqrt(abs(l - (x[j] - x[i])).toDouble()) - mid * b[j] if (ft < dp[j]) { dp[j] = ft pr[j] = i } } } if (dp[n - 1] <= 0) { high = mid res.clear() var i = n - 1 while (i > 0) { res.add(i) i = pr[i] } res.reverse() } else { low = mid } } println(res.joinToString(" ")) }