#K47992. Maximum Distance Between Consecutive Lit Houses
Maximum Distance Between Consecutive Lit Houses
Maximum Distance Between Consecutive Lit Houses
You are given a row of n houses (numbered from 1 to n). Some of these houses have their lights turned on. Your goal is to determine the maximum distance between any two consecutive houses that have their lights on.
If there are fewer than two houses with lights on, the answer is 0. Otherwise, consider the positions of the houses with lights on (which may be given in an unsorted order) and compute the maximum difference between consecutive positions.
The problem can be mathematically described as follows: Let \(L = [l_1, l_2, \dots, l_m]\) be the sorted positions (i.e. in increasing order) of houses with lights on. If \(m < 2\), then the answer is 0. Otherwise, compute
[ \text{max extunderscore distance} = \max_{1 \le i < m} (l_{i+1} - l_i) ]
Output the computed maximum distance.
inputFormat
The input is given via standard input (stdin) and consists of two parts:
- An integer
n
that represents the total number of houses. - An integer
m
that represents the number of houses with lights on, followed bym
integers specifying the house numbers that have their lights on.
Note: The list of lit houses is not guaranteed to be sorted.
outputFormat
Print a single integer which is the maximum distance between any two consecutive houses with the lights on. The output should be printed to standard output (stdout).
## sample10
4
3 5 8 9
3
</p>