Mock CCC '20 Contest 1 J5 - Finding Number of Pairs

View as PDF

Submit solution

Points: 10
Time limit: 2.0s
Memory limit: 64M

Problem type

Given a sequence of n integers A[1], A[2], \dots, A[n] and a positive integer M, count the number of pairs (i, j) that satisfy the following two conditions:

  • i < j, and
  • A[i] + A[j] \le M.

Input Specification

The first line contains integer n\ ( 2 \le n \le 10^5 ) and M\ ( 0 \le M \le 10^9 ), separated by a space.
The second line contains n integers, which denotes A[1], A[2], \dots , A[n]\ (0 \le A[i] \le 10^9).
In 50% of the test cases, n \le 1\,000.

Output Specification

The output contains an integer, which denotes the number of pairs that satisfies the two conditions. If the output is smaller than 10^9+7, please keep it as is. Otherwise, output the number mod 10^9+7.

Sample Input 1

5 6
1 2 3 4 5

Sample Output 1

6

Explanation for Sample Output 1

Among the pairs, (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4) satisfy the conditions.

Sample Input 2

5 12
3 6 8 2 8

Sample Output 2

7

Explanation for Sample Output 2

(1, 2), (1, 3), (1, 4), (1, 5), (2, 4), (3, 4), (4, 5) satisfy the conditions.


Comments

There are no comments at the moment.