#BST0000003. Giá trị nhỏ nhất và lớn nhất (Minimum and Maximum in a BST)
Giá trị nhỏ nhất và lớn nhất (Minimum and Maximum in a BST)
Minimum and Maximum in a BST
Source: Phuoc Hung OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Start with an empty BST. Insert in the given order: smaller keys go left, larger keys go right, and a new node is created at the first empty child position. If a key already exists, ignore that duplicate insertion.
After the tree is built, determine the smallest and the largest key currently stored in the BST.
Input
The first line contains .
If , the next line contains signed integers in insertion order. If , this line is absent.
Output
If the tree is empty, print EMPTY.
Otherwise print two integers on one line: the minimum key followed by the maximum key.
Subtasks
Subtask 1 (20 points): .
Subtask 2 (30 points): .
Subtask 3 (50 points): .
In all subtasks, every is a signed 64-bit integer. Duplicate keys are ignored.
Examples
Input
7
8 3 10 1 6 14 4
Output
1 14
Explanation
After all insertions, the stored keys are . The minimum is and the maximum is , so the program prints 1 14.