#K32917. Is the Shelf Sorted?
Is the Shelf Sorted?
Is the Shelf Sorted?
You are given the number of books n on a shelf and a sequence of n integers representing the heights of the books in the order they are arranged. Your task is to determine whether the books are arranged in non-decreasing order by height.
If the sequence of heights is sorted in non-decreasing order, print YES
. Otherwise, print NO
.
The comparison should follow the mathematical form of:
\(h_1 \leq h_2 \leq \dots \leq h_n\)
where \(h_i\) represents the height of the \(i\)-th book.
inputFormat
The first line contains an integer n (\(1 \le n \le 10^5\)), the number of books on the shelf. The second line contains \(n\) space-separated integers representing the height of each book (each height is an integer between 1 and 10^9).
outputFormat
Output a single line containing YES
if the sequence is sorted in non-decreasing order, or NO
otherwise.
5
120 150 150 180 200
YES
</p>