#K15131. Maximum Buildings Visible

    ID: 24289 Type: Default 1000ms 256MiB

Maximum Buildings Visible

Maximum Buildings Visible

In this problem, you are given (N), the number of buildings, and a list of building heights. For each building, you need to determine the total number of buildings visible in both directions. A building (i) can see another building (j) if all buildings between them are strictly shorter than the building being observed. Formally, for each building (i), the number of visible buildings is defined as [ visible(i) = visible_{left}(i) + visible_{right}(i), ] where [ visible_{left}(i) = #{j: j < i \text{ and } h_j > \max_{k=j+1}^{i-1} h_k}, ] [ visible_{right}(i) = #{j: j > i \text{ and } h_j > \max_{k=i+1}^{j-1} h_k}. ] Your task is to output the maximum value of (visible(i)) over all buildings (i).

inputFormat

The first line of input contains an integer (N), the number of buildings. The second line contains (N) space-separated integers representing the heights of the buildings.

outputFormat

Output a single integer which is the maximum number of buildings visible from any one building.## sample

7
4 2 3 7 8 5 1
4