SIO-Knjige
Jack the book worm likes it best when shelves with books are tidy, so he sometimes puts them in order during the night. He is tiny, but very strong. When he has eaten, he can easily carry more books.One evening he found a pile of books at the middle of the shelf. Each of the books has it's position on the shelf. Let's designate the position where Jack found the books with 0. Positive integers will be the positions right from the place where he is, and negative ones will be left. In order to travel from one position to another, Jack has to make a footstep. The length he passed is counted with the numbers of steps he had to make to put all the books in order. For example, if Jack carries two books and has to put them on the positions 3 and 5, he has to make 10 steps, because he has to go to position 5 and to return to position 0, and will place the book "3" while on his way to position 5. Whenever Jack returns to position 0, he mustn't carry any books. Write a program which calculates the minimal route Jack has to travel in order to put all books in order.
2
8
1
0
10
-2
5
-4
2
-5Output:
38Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.