#K8826. Sunlit Buildings

    ID: 37269 Type: Default 1000ms 256MiB

Sunlit Buildings

Sunlit Buildings

In this problem, you are given a sequence of building heights. The sun rises in the east (from the left side), and a building receives sunlight only if it is strictly taller than every building to its left. Your task is to determine the number of buildings that will receive sunlight for each test case.

Explanation: For each test case, iterate through the list of building heights. A building receives sunlight when its height is greater than the maximum height encountered so far from the left. Mathematically, for a sequence of heights \(a_1, a_2, \dots, a_n\), the number of sunlit buildings is given by:

[ \text{count} = \sum_{i=1}^{n} \left[ a_i > \max_{1 \leq j < i} a_j \right] ]

where \([\text{condition}]\) is 1 if the condition is true, and 0 otherwise.

inputFormat

The input begins with an integer T representing the number of test cases. Each test case consists of two lines. The first line contains an integer n, the number of buildings. The second line contains n space-separated integers representing the heights of the buildings from left to right.

outputFormat

For each test case, output a single line containing one integer - the number of buildings that receive sunlight.## sample

1
5
3 5 4 6 2
3