TSS '19 CC P2 - Counting Pairs

View as PDF

Submit solution


Points: 7
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Given a sequence of N integers a_1, a_2, \ldots, a_N, and a positive integer M, count the number of pairs (i, j) such that a_i + a_j \leq M and i < j.

Input Specification

The first line contains an integer N ( 2 \leq N \leq 10^5 ) and M ( 0 \leq M \leq 10^9 ).

The second line contains N integers, which denotes a_1, a_2, \ldots, a_N, ( 0 \leq a_i \leq 10^9 ).

In 50\% of the test cases, N \leq 1000.

Output Specification

The output contains an integer, which denotes the number of pairs. Note that the answer could be too large to fit into a 32-bit integer.

Sample Input 1

5 6
1 2 3 4 5

Sample Output 1

6

Sample Input 2

5 12
3 6 8 2 8

Sample Output 2

7

Comments

There are no comments at the moment.