Counting Student Pairs

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Châu Nhật Tăng
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Teacher ~Jack~ from the elementary school is teaching ~ n ~ students how to ride a bicycle. The students are numbered from ~1~ to ~ n~, and student ~ j ~ has a weight of ~ a_j ~. There is a single bicycle with a maximum weight capacity of ~ m ~. Two students can ride the bicycle together if their combined weight does not exceed ~ m ~.

Teacher ~Jack~ is wondering how many ways there are to choose two different students to ride together. After many hours of calculations without results, she decided to ask programming experts to solve the Counting Student Pairs (CSP) problem.

Requirement:

  • Count the number of pairs ~ (i, j) ~ where ~ i < j ~ and ~ a_i + a_j \leq m ~.

Input

  • The first line contains two positive integers ~ n ~ and ~ m ~ (~ n, m \leq 10^6 ~).
  • The second line contains ~ n ~ positive integers ~ a_1, a_2, \ldots, a_n ~ (~ \forall i: a_i \leq 10^6 ~).

Output

  • Print a single integer representing the number of valid pairs.

Sample Input

5 6
1 2 3 4 5

Sample Output

6

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.