#C6017. Counting Increasing Pairs

    ID: 49731 Type: Default 1000ms 256MiB

Counting Increasing Pairs

Counting Increasing Pairs

You are given an array of N integers representing heights. Your task is to count the number of pairs (i, j) such that (1 \le i < j \le N) and (H[i] < H[j]). In other words, count the number of pairs where the height at the earlier index is strictly less than the height at the later index.

For example, if the array is [2, 1, 5, 4, 3] (with N = 5), the answer is 6 because there are 6 valid pairs (i, j) that satisfy the condition.

This is an easy problem that can be solved with a simple nested loop or an optimized approach if necessary. Note that the indices are based on the 1-indexed array for the condition, but implementation may use 0-indexing.

inputFormat

The input consists of two lines:

  1. The first line contains one integer \(N\), the number of elements in the array.
  2. The second line contains \(N\) space-separated integers representing the array \(H\).

outputFormat

Output a single integer representing the number of valid pairs \((i, j)\) such that \(H[i] < H[j]\) and \(i < j\).

## sample
5
2 1 5 4 3
6