#C10184. Counting Rolling Balls

    ID: 39361 Type: Default 1000ms 256MiB

Counting Rolling Balls

Counting Rolling Balls

In this problem, you are given a sequence of integers representing the heights of adjacent buildings. A ball can roll from building i to building i+1 if the height of the i-th building is strictly less than the height of the i+1-th building. In other words, for an array of heights \( h_0, h_1, \dots, h_{n-1} \), a ball will roll from building \( i \) to building \( i+1 \) if and only if \( h_i < h_{i+1} \). Your task is to compute the total number of such successful transitions.

Example:

  • For input heights: [10, 5, 8, 11, 6, 9], the valid adjacent pairs are (5,8), (8,11) and (6,9), so the output is 3.
  • For input heights: [1, 2, 3, 4, 5], every consecutive pair satisfies the condition, so the output is 4.

inputFormat

The input is read from standard input (stdin). The first integer \( N \) represents the number of buildings. It is followed by \( N \) integers representing the heights of the buildings separated by spaces.

For example:

6
10 5 8 11 6 9

outputFormat

Output a single integer to standard output (stdout) representing the number of adjacent building pairs where a ball can roll from the left building to the right, i.e., where \( h_i < h_{i+1} \) holds.

## sample
6
10 5 8 11 6 9
3

</p>