#K64397. Longest Stable Memory Period
Longest Stable Memory Period
Longest Stable Memory Period
This problem requires you to analyze a sequence of memory usage values to determine the longest continuous subarray in which each value does not exceed a specified threshold.
More formally, you are given an integer \(n\) denoting the number of memory usage values, an integer \(t\) representing the threshold, and a sequence \(a_1, a_2, \ldots, a_n\). You are to find indices \(i\) and \(L\) such that the subarray \(a_i, a_{i+1}, \ldots, a_{i+L-1}\) satisfies \(a_j \le t\) for all \(j = i, i+1, \ldots, i+L-1\) and \(L\) is maximized. The answer should report the starting index (1-indexed) and the length \(L\) of this subarray. If no such element exists then the length is 0 and the starting index is defined to be 1.
inputFormat
The input is given from stdin and consists of two lines:
- The first line contains two space-separated integers \(n\) and \(t\), where \(n\) is the number of memory usage measurements and \(t\) is the threshold.
- The second line contains \(n\) space-separated integers representing the memory usage values.
You can assume that \(1 \le n \le 10^5\) and the values are integers.
outputFormat
Print to stdout two integers separated by a space: the 1-indexed starting position of the longest contiguous subsequence where each memory usage is at most \(t\), and the length of this subsequence.
If there is no memory usage value within the threshold, output should be "1 0".
## sample5 4
1 2 3 4 5
1 4