#K61227. Minimum Tree Tax
Minimum Tree Tax
Minimum Tree Tax
You are given n trees with heights represented as an array \(H = [h_1, h_2, \ldots, h_n]\). You are allowed to remove at most one tree from this array. After the removal, the tax is defined as the height of the tallest tree remaining, i.e. \(T = \max\{h'_1, h'_2, \ldots\}\), where \(H'\) represents the heights of the remaining trees.
Your task is to determine the minimum possible tax you can achieve by removing at most one tree. In particular, if there are exactly two trees, you should remove the taller one, making the tax equal to the height of the shorter tree.
Example: For \(n = 5\) and \(H = [2, 3, 9, 7, 4]\), if you remove the tree with height 9, the remaining heights are \([2, 3, 7, 4]\), so the tax becomes \(7\), which is the minimum possible.
inputFormat
The first line of input contains an integer \(n\), the number of trees. The second line contains \(n\) space-separated integers representing the heights of the trees.
outputFormat
Output a single integer representing the minimum possible tax (i.e. the height of the tallest remaining tree) after removing at most one tree.
## sample5
2 3 9 7 4
7