#K71672. Count Valid Pair Sums

    ID: 33584 Type: Default 1000ms 256MiB

Count Valid Pair Sums

Count Valid Pair Sums

You are given an array of integers and a threshold value \(X\). Your task is to count the number of pairs \((i, j)\) with \(i < j\) such that the sum of the two elements satisfies \(arr[i] + arr[j] \leq X\).

For example, for the array [1, 2, 3, 4] and \(X = 5\), the valid pairs are:

  • (1, 2) because 1 + 2 = 3 \(\leq 5\)
  • (1, 3) because 1 + 3 = 4 \(\leq 5\)
  • (1, 4) because 1 + 4 = 5 \(\leq 5\)
  • (2, 3) because 2 + 3 = 5 \(\leq 5\)

Your solution should read from stdin and output the result to stdout.

inputFormat

The first line contains two space-separated integers \(n\) and \(X\), where \(n\) is the number of elements in the array and \(X\) is the threshold value. The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

Output a single integer representing the number of valid pairs \((i, j)\) such that \(arr[i] + arr[j] \leq X\) with \(i < j\).

## sample
4 5
1 2 3 4
4