eolymp
bolt
Try our new interface for solving problems
Problems

Platforms

Platforms

In older games one can run into the next situation. The hero jumps along the platforms that hang in the air. He must move himself from one side of the screen to the other. When the hero jumps from one platform to the neighboring, he spends $|y_2 - y_1|$ energy, where $y_1$ and $y_2$ are the heights where these platforms hang. The hero can make a super jump that allows him to skip one platform, but it takes him $3 \cdot |y_3 - y_1|$ energy. You are given the heights of the platforms in order from the left side to the right. Find the minimum amount of energy to get from the $1$-st (start) platform to the $n$-th (last). Print the list (sequence) of the platforms that the hero must pass. \InputFile The first line contains the number of platforms $n~(2 \le n \le 10^5)$. The second line gives $n$ integers --- the heights of the platforms, which absolute values are not grater than $4000$. \OutputFile Print in the first line the minimum amount of energy to get from the $1$-st platform to the $n$-th. Print in the second line the number of platforms to pass. Give in the third line the list of these platforms. \includegraphics{https://eolympusercontent.com/images/op6i6qnagd34h81m1q99cs2ffc.gif}
Time limit 2 seconds
Memory limit 128 MiB
Input example #1
4
1 2 3 30
Output example #1
29
4
1 2 3 4
Input example #2
6
4 6 15 5 10 12
Output example #2
12
5
1 2 4 5 6