#K79152. Smallest Subarray Removal for Sorted Array

    ID: 35245 Type: Default 1000ms 256MiB

Smallest Subarray Removal for Sorted Array

Smallest Subarray Removal for Sorted Array

You are given an array of n integers. Your task is to find the smallest continuous subarray such that, if it is removed, the remaining array (i.e. the concatenation of the left and right parts) is sorted in non-decreasing order.

The indices of the subarray to remove should be reported as 1-indexed positions. If the array is already sorted or contains a single element, output 1 1 (i.e. remove a dummy subarray).

Note: A sequence a is said to be sorted in non-decreasing order if for every i with \(1 \le i < n\), \(a_i \le a_{i+1}\).

inputFormat

The first line contains an integer n (\(0 \le n \le 10^5\)), the number of elements in the array.

The second line contains n integers separated by spaces representing the elements of the array. If n = 0, the second line will be empty.

outputFormat

Output two integers separated by a space representing the 1-based start and end indices of the smallest continuous subarray to remove so that the remaining array is sorted in non-decreasing order.

## sample
5
1 3 5 7 9
1 1

</p>