#K85072. Maximum Consecutive Productive Hours

    ID: 36560 Type: Default 1000ms 256MiB

Maximum Consecutive Productive Hours

Maximum Consecutive Productive Hours

You are given an integer n representing the number of hours, an array ratings of length n where each element represents the productivity rating of an hour, and an integer threshold. An hour is considered "productive" if its rating is strictly greater than the threshold.

Your task is to compute the maximum number of consecutive productive hours. In other words, find the longest contiguous segment in the ratings array where every rating is greater than threshold.

Formally, if the ratings are given by \(a_1, a_2, \dots, a_n\) and the threshold is \(T\), you need to find the maximum length \(L\) such that there exists an index \(i\) for which \(a_i > T, a_{i+1} > T, \dots, a_{i+L-1} > T\). If no rating is greater than \(T\), the answer is 0.

Example 1: For n = 6, ratings = [7, 10, 4, 4, 8, 9] and threshold = 5, the productive hours are at indices 1 and 2 (7 and 10) and again at indices 5 and 6 (8 and 9). Thus, the maximum consecutive productive hours is 2.

Example 2: For n = 5, ratings = [1, 3, 5, 7, 9] and threshold = 3, the longest sequence of consecutive ratings greater than 3 is [5, 7, 9], which has a length of 3.

inputFormat

The input is read from stdin and consists of three lines:

  1. The first line contains a single integer n (\(1 \leq n \leq 10^5\)), representing the number of hours.
  2. The second line contains \(n\) space-separated integers representing the productivity ratings for each hour.
  3. The third line contains a single integer threshold.

outputFormat

Output a single integer to stdout which is the maximum number of consecutive hours with a productivity rating strictly greater than the given threshold.

## sample
6
7 10 4 4 8 9
5
2