#C9791. Maximum Buildings Visited

    ID: 53923 Type: Default 1000ms 256MiB

Maximum Buildings Visited

Maximum Buildings Visited

You are given an array of n integers, where each integer represents the height of a building. A person starts on the first building and can visit subsequent buildings only if the building’s height is less than or equal to the height of the building they are currently on. The traversal must always move strictly to the right; in other words, once the person moves to a new building, they cannot go back. The task is to determine the maximum number of buildings the person can visit, starting from the first building.

The jump condition can be expressed mathematically as follows. Let the array of building heights be \(h_1, h_2, \dots, h_n\). The person can visit building \(i+1\) only if:

[ h_{i+1} \leq h_i ]

Once a building is encountered that does not satisfy this condition, the traversal stops.

inputFormat

The input is given via standard input (stdin) and has the following format:

T
N₁
h₁₁ h₁₂ ... h₁ₙ₁
N₂
h₂₁ h₂₂ ... h₂ₙ₂
...
N_T
h_T₁ h_T₂ ... h_Tₙₜ

Where:

  • T is the number of test cases.
  • For each test case, the first line contains an integer N representing the number of buildings.
  • The following line contains N space-separated integers representing the heights of the buildings.

outputFormat

For each test case, output the maximum number of buildings that can be visited. Each answer should be printed on its own line to standard output (stdout).

## sample
3
6
3 2 1 2 3 4
5
5 4 3 2 1
4
1 2 3 4
3

5 1

</p>