#C1869. Move One Person to Form a Strictly Increasing Sequence
Move One Person to Form a Strictly Increasing Sequence
Move One Person to Form a Strictly Increasing Sequence
You are given an integer n and a sequence of n integers representing the heights of people standing in a line. Your task is to move exactly one person (i.e. remove one element and reinsert it at a different position) so that the resulting sequence becomes strictly increasing. A sequence \(a_1, a_2, \dots, a_n\) is strictly increasing if \(a_i < a_{i+1}\) for all \(1 \le i < n\).
If the sequence is already strictly increasing, simply output it. If there exists a move (removing one person and reinserting them at the appropriate position) that results in a strictly increasing sequence, output that modified sequence. Otherwise, output -1
.
Note: The input is provided via standard input and the output should be printed to standard output.
inputFormat
The first line contains a single integer n (the number of people). The second line contains n space-separated integers representing the heights of the people.
outputFormat
If it is possible to obtain a strictly increasing sequence by moving exactly one person, output the sequence as n space-separated integers in a single line. If not, output -1
.
5
1 2 7 4 5
1 2 4 5 7