#C4245. Counting Sunset Buildings

    ID: 47762 Type: Default 1000ms 256MiB

Counting Sunset Buildings

Counting Sunset Buildings

You are given a sequence of n buildings in a row, each with a specified height. A building has an unobstructed view of the sunset if there are no buildings to its right that are of greater or equal height. Your task is to count the number of buildings that can see the sunset.

Note: The buildings are considered from left to right as they appear in the input. The sunset is assumed to be in the west, hence a building can view the sunset if no building to its right is taller or equal in height.

Example:
For the input list of heights: [3, 5, 4, 4, 2, 3, 1], the buildings with heights 1, 3, 4, and 5 have an unobstructed view. Thus, the answer is 4.

inputFormat

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

  • The first line contains a single 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

Output a single integer to stdout, which is the number of buildings that have an unobstructed view of the sunset.

## sample
1
10
1