Problem C
Tree Shopping

Andy is going holiday shopping and needs to buy several Christmas trees. At the store, there is a row of Christmas trees of various heights. Andy is only allowed to buy trees that are next to each other, i.e. trees that are contiguous within the row. He also wants to make sure that the shortest tree he buys and the tallest tree he buys are as close in height as possible. What is the smallest height difference he can get given the constraints?
Input
The input consists of two lines. The first line contains two
integers
Output
Output the minimum height difference between the shortest
and tallest trees of any contiguous subrange of
Sample Input 1 | Sample Output 1 |
---|---|
10 2 1 3 5 7 9 11 13 15 17 16 |
1 |
Sample Input 2 | Sample Output 2 |
---|---|
5 4 1 1 3 5 6 |
4 |