#C622. Longest Peak in a Hike
Longest Peak in a Hike
Longest Peak in a Hike
You are given a hiking trail's elevation profile represented by M integer values, where each value indicates the elevation at a mile marker. A peak is defined as a contiguous segment of the trail that first strictly increases and then strictly decreases. The peak must consist of at least three points (an increasing sequence, a peak, and a decreasing sequence).
Your task is to determine the length of the longest peak and the starting mile marker (1-indexed) of that longest peak. If no valid peak exists, print 0 -1
.
Note: In the case of multiple peaks, if more than one has the maximum length, output the one that starts earliest.
inputFormat
The input consists of two lines:
- The first line contains an integer M, denoting the number of elevation records.
- The second line contains M space-separated integers which represent the elevation values at each mile marker.
outputFormat
Output two integers separated by a space: the length of the longest peak and the starting mile marker (1-indexed) where that peak begins. If no peak exists, output 0 -1
.
10
1 3 2 1 4 6 4 1 2 3
5 4