#C8405. Longest Scenic Segment
Longest Scenic Segment
Longest Scenic Segment
You are given a sequence of elevation measurements along a route. Your task is to determine the longest contiguous segment of the route where each subsequent elevation is strictly higher than the previous one. Formally, given an integer \(n\) representing the number of segments and an array of integers \(elevations\), compute the maximum length \(L\) such that in some contiguous subarray of elevations, every adjacent pair satisfies \(elevations[i] < elevations[i+1]\). Note that if \(n = 1\) the answer is always 1.
The problem can be formalized as follows:
Given \(n\) and an array \(elevations[0 \ldots n-1]\), find the maximum integer \(L\) for which there exists an index \(i\) with: \[ elevations[i] < elevations[i+1] < \cdots < elevations[i+L-1] \]
Your solution must read from standard input and write the result to standard output.
inputFormat
The input is given via standard input in the following format:
n a1 a2 a3 ... an
Where:
n
is an integer representing the number of elevation measurements.a1, a2, ..., an
are the elevation values.
outputFormat
Output a single integer representing the length of the longest scenic (strictly increasing) segment.
## sample7
2 2 3 4 1 5 6
3
</p>