#K4601. Minimum Height Difference
Minimum Height Difference
Minimum Height Difference
Given a number of trees and their respective heights, arrange the trees in such a way that the adjacent height difference is minimized. In particular, you are given \(N\) trees with heights \(h_1, h_2, \dots, h_N\). The optimal arrangement is obtained by sorting the trees in non-decreasing order, and then the minimum height difference is computed between every pair of adjacent trees.
If there is only one tree (i.e. \(N = 1\)), output inf
to represent an infinite gap.
Your task is to write a program that reads the tree count and heights from standard input, computes the minimum adjacent height difference, and prints the result to standard output.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(N\) representing the number of trees.
- The second line contains \(N\) space-separated integers representing the heights of the trees.
outputFormat
Output a single line containing the minimum height difference between any two adjacent trees when arranged in non-decreasing order. If \(N = 1\), output inf
.
1
4
inf