#C634. Almost Sorted Array
Almost Sorted Array
Almost Sorted Array
You are given an array (A) of (n) integers. The array is defined to be almost sorted if it is already in non-decreasing order or it can be converted to a non-decreasing array by removing exactly one element. In other words, if by removing one element (or none) the remaining array satisfies (A[i] \le A[i+1]) for all valid indices, then the array is almost sorted.
Your task is to determine if the given array is almost sorted.
Note: The removal of an element is an optional operation. If the array is already sorted, it is considered almost sorted.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer (n) ( (1 \le n \le 10^5) ), representing the number of elements in the array.
- The second line contains (n) space-separated integers, representing the elements of array (A).
outputFormat
Output a single line to standard output (stdout) containing the string "YES" if the array is almost sorted, otherwise output "NO".## sample
5
1 2 3 4 5
YES
</p>