Lecture Rooms
InterviewTime limit1sMemory limit1024 MB
Given N lecture room positions on a line and at most K teleports from x=0, find the minimum walking time to visit every room.
Problem
Hyeokjun has to attend lectures today. Every lecture is held in a lecture room at a different coordinate on the -axis. The -th lecture room is at , and Hyeokjun starts at . Each move of 1 to the left or right along the -axis takes second. Hyeokjun is a novice wizard and can teleport at most times. A teleport moves him instantly from his current position to any other position he chooses, and it takes no time. Find the minimum time for Hyeokjun to start at and visit every lecture room once. Attending a lecture takes no time.
Input
The first line contains integers and . (; )
The next line contains the distinct integers that give the positions of the lecture rooms, separated by spaces. ()
Output
Print the minimum time for Hyeokjun to visit every lecture room once.