#K14051. Beautiful Permutation
Beautiful Permutation
Beautiful Permutation
You are given a permutation of the integers from 1 to \(n\). A permutation is considered beautiful if there are no two consecutive elements that form a decreasing pair. In other words, the permutation \(P = [p_1, p_2, \ldots, p_n]\) is beautiful if for every index \(i\) \( (1 \leq i < n)\), the condition \(p_i \leq p_{i+1}\) holds.
Your task is to determine whether the given permutation is beautiful.
Example
Input: 5 1 2 3 4 5</p>Output: YES
inputFormat
The input is given via STDIN and consists of two lines:
- The first line contains a single integer \(n\), the length of the permutation.
- The second line contains \(n\) space-separated integers representing the permutation.
outputFormat
Print a single line to STDOUT with the answer: print YES
if the permutation is beautiful, or NO
otherwise.
5
1 2 3 4 5
YES
</p>