Reference: https://www.hackerrank.com/challenges/flatland-space-stations/problem
Flatland is a country with a number of cities, some of which have space stations. Cities are numbered consecutively and each has a road of
For example, there are
The first line consists of two space-separated integers,
The second line contains
$1 \leq n \leq 10^{5}$ $1 \leq m \leq n$ - There will be at least
$1$ city with a space station. - No city has more than one space station.
Print an integer denoting the maximum distance that an astronaut in a Flatland city would need to travel to reach the nearest space station.
5 2
0 4
2
This sample corresponds to following graphic:
The distance to the nearest space station for each city is listed below:
-
$c[0]$ has distance -$0 km$ , as it contains a space station. -
$c[1]$ has distance -$1 km$ , to the space station in$c[0]$ . -
$c[2]$ has distance -$2 km$ , to the space stations in$c[0]$ and$c[4]$ . -
$c[3]$ has distance -$1 km$ , to the space station in$c[4]$ . -
$c[4]$ has distance -$0 km$ , as it contains a space station.
We then take
6 6
0 1 2 4 3 5
0
In this sample,
