#K70722. Non-decreasing Array Modification
Non-decreasing Array Modification
Non-decreasing Array Modification
You are given an array of integers. Your task is to determine whether it is possible to modify at most one element of the array so that the resulting sequence is non-decreasing. In other words, after at most one modification, the array should satisfy:
If it is possible, print YES
; otherwise, print NO
.
Note: Modification means changing the value of an element to any integer.
inputFormat
The input consists of two lines:
- The first line contains a single integer
n
(the number of elements in the array). - The second line contains
n
space-separated integers representing the array.
outputFormat
Output a single line with YES
if the array can be made non-decreasing by modifying at most one element, or NO
otherwise.
3
4 2 3
YES
</p>