Psychopathic elevator

Sometimes, professor Oak has to use a certain public elevator. That
elevator works so badly, is so slow and takes such stupid decisions
(going up or down) that it seems ruled by some insane spirit. Or, more
likely, the programmer of the elevator had some mental disorder…

Given all the floors that must be visited, and the initial floor of the
elevator, your task is to compute the minimum possible distance and the
maximum possible distance to visit all the floors. Only movements
beetween required floors are allowed.

Input

Input consists of several cases, each one with the initial floor f of
the elevator, followed by the number n of floors to be visited, followed
by n numbers in ascending order. Assume 1 ≤ n ≤ 10⁶. All floor numbers,
including f, are different and between 1 and 10⁹.

Output

For every case, print the minimum and the maximum possible distances to
visit all the required floors starting from the initial floor.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:08:41.393Z

© Jutge.org, 2006–2026.
https://jutge.org
