#K57742. Make It Strictly Increasing
Make It Strictly Increasing
Make It Strictly Increasing
You are given a sequence of n blocks, each with a given height. Your task is to determine whether it is possible to obtain a strictly increasing sequence of heights by removing at most one block from the sequence.
A sequence A = [a1, a2, ..., an] is strictly increasing if for every i (1 ≤ i < n), the following inequality holds:
$$a_i < a_{i+1}$$
If the sequence is already strictly increasing or can be made strictly increasing by removing just one element, output YES
. Otherwise, output NO
.
inputFormat
The first line of input contains an integer n (1 ≤ n ≤ 105), representing the number of blocks. The second line contains n space-separated integers denoting the heights of the blocks.
outputFormat
Output a single line containing YES
if it is possible to obtain a strictly increasing sequence by removing at most one block; otherwise output NO
.
6
1 2 10 5 7 8
YES