Problem Statement | |||||||||||||
Disk Scheduling is an important component of an operating system. The disk (or hard-drive) is composed of a number of cylinders. Each cylinder contains circular tracks, which in turn are divided into sectors. To read a particular sector the operating system must determine the cylinder and track it belongs to. It then rotates the cylinder so that the disk head is positioned at the desired sector. If the file being used is located on numerous sectors, scattered across the track, the disk scheduler must read all those sectors in such a way that minimizes total head movement. In practice it is impossible to implement an optimal disk scheduling algorithm, because requests to read sectors arrive one after another, instead of being known from the start. However, in our problem the order that the sectors are read can be changed to suit the fastest retrieval. The results of a theoretical optimal algorithm are useful when comparing the effectiveness of various real-life scheduling algorithms. For the purpose of this problem assume that a track has 100 sectors numbered from 1 to 100 inclusive. The cylinder can be rotated either clockwise or counter-clockwise. The cylinder is circular meaning that sector 1 is adjacent to sector 100. Given the start location of the head determine the minimal head movement required to read all the int[] sectors. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | start will be between 1 and 100 inclusive. | ||||||||||||
- | sectors will contain between 1 and 50 elements inclusive. | ||||||||||||
- | each element in sectors will be between 1 and 100 inclusive. | ||||||||||||
- | sectors will not have any repeated elements. | ||||||||||||
- | start will never be an element of sectors. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|