#C2737. Special Soldier Formation
Special Soldier Formation
Special Soldier Formation
You are given N soldiers with known heights. Your task is to determine whether it is possible to rearrange the soldiers into a special formation such that every soldier has exactly one taller soldier standing in front of him. In order for such a formation to exist, every soldier must have a unique height. That is, if the heights of the soldiers are given by \(h_1, h_2, \dots, h_N\), then the formation is possible if and only if \(h_i \neq h_j\) for all \(i \neq j\).
Input Format: The first line contains an integer \(N\) representing the number of soldiers. The second line contains \(N\) space-separated integers representing the heights of the soldiers.
Output Format: Output a single line: YES
if the formation is possible, or NO
otherwise.
inputFormat
The input consists of two lines:
- The first line contains an integer \(N\), the number of soldiers.
- The second line contains \(N\) space-separated integers representing the heights of the soldiers.
outputFormat
Output a single line: YES
if it is possible to arrange the soldiers into the special formation; otherwise, output NO
.
5
5 4 3 2 1
YES