#K41482. Minimum Adjacent Difference

    ID: 26875 Type: Default 1000ms 256MiB

Minimum Adjacent Difference

Minimum Adjacent Difference

You are given an array of integers. Your task is to reorder (or simply sort) the array so that the difference between some pair of consecutive elements is as small as possible. In other words, compute ( \min_{1 \le i < n} (a_{i+1} - a_i) ) after sorting the array in non-decreasing order. Note that if the array contains only one element, then no two elements exist so the minimized maximum difference is defined to be ( \infty ).

For example, given the array [1, 2, 3, 4], after sorting it remains [1, 2, 3, 4] and the differences between consecutive elements are all 1, so the answer is 1. Given [8, 9, 6, 2, 4], sorting gives [2, 4, 6, 8, 9] where the differences are [2, 2, 2, 1] and the minimum difference is 1.

inputFormat

The first line of input contains an integer ( n ) (the number of elements in the array).

The second line contains ( n ) space-separated integers representing the array elements.

outputFormat

Output a single line: the minimum difference between any two consecutive elements after sorting. If ( n<2 ) (i.e. the array has only one element), print inf (without quotes) to represent infinity.## sample

4
1 2 3 4
1

</p>