#K61162. Almost Sorted Sequence
Almost Sorted Sequence
Almost Sorted Sequence
Given an array of integers, determine whether it is possible to remove at most one element such that the remaining sequence is non-decreasing. In other words, check if there exists a way to remove one element (or none) so that the resulting sequence satisfies
where \(A\) is the sequence after removal. If such a removal is possible, output YES
; otherwise, output NO
.
Note: A sequence with a single element or a sequence that is already non-decreasing is considered valid.
inputFormat
The first line contains an integer \(n\) denoting the number of elements in the array. The second line contains \(n\) space-separated integers representing the array.
outputFormat
Output a single line containing YES
if the array can be converted into a non-decreasing sequence by removing at most one element, otherwise output NO
.
5
10 5 7 10 12
YES
</p>