#K36482. Maximize LCIS with a Single Subarray Reversal
Maximize LCIS with a Single Subarray Reversal
Maximize LCIS with a Single Subarray Reversal
You are given an array of n distinct integers. Your task is to reverse exactly one continuous subarray (i.e. a contiguous segment) of the given array in order to maximize the length of the Longest Contiguous Increasing Subsequence (LCIS).
After reversing the chosen subarray, the elements in that segment will appear in the opposite order. In case multiple subarrays yield the same maximum LCIS length, you must choose the subarray that results in the lexicographically smallest overall array.
If no reversal can result in any improvement (i.e. the array is already entirely increasing), output 1 1
indicating that no reversal is necessary.
Note: The lexicographical order between two arrays A and B is defined as follows: Let i be the first index at which A[i]
and B[i]
differ. The array with the smaller element at index i is considered lexicographically smaller. If no such index exists, the arrays are equal.
The indices are 1-indexed and must satisfy \(1 \le l \le r \le n\), where l
and r
are the starting and ending positions of the subarray to be reversed.
inputFormat
The input consists of two lines:
- The first line contains a single integer n denoting the number of elements in the array.
- The second line contains n space-separated distinct integers.
outputFormat
Output two integers l
and r
(separated by a space) that represent the 1-indexed starting and ending positions of the subarray which, when reversed, maximizes the LCIS of the array. If no reversal improves the LCIS, output 1 1
.
Note: The indices must satisfy \(1 \le l \le r \le n\).
## sample6
1 5 4 3 2 6
2 5