C - ペアの合計点 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 366

問題文

青木先生のクラスでは N 人の生徒がテストを受けました。生徒にはそれぞれ 1 から N までの出席番号が付けられており、生徒 i の得点は A_i 点です。

青木先生は、異なる 2 人の生徒をペアにしてグループワークを行わせることを考えています。ペアの実力を測る指標として、 2 人の得点の合計を「ペアスコア」と定義します。

青木先生は、ペアスコアがある基準値 K 以上となるペアがいくつあるかを知りたいと思っています。

2 人の異なる生徒の組 (i, j)1 \leq i < j \leq N )のうち、 A_i + A_j \geq K を満たすものの個数を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 2 \times 10^9
  • 1 \leq A_i \leq 10^91 \leq i \leq N
  • 入力はすべて整数である。

入力

N K
A_1 A_2 \ldots A_N
  • 1 行目には、生徒の人数を表す整数 N と、ペアスコアの基準値を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各生徒の得点を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。

出力

ペアスコアが K 以上となるペアの個数を 1 行で出力せよ。


入力例 1

4 6
1 3 5 7

出力例 1

5

入力例 2

3 10
1 2 3

出力例 2

0

入力例 3

10 15
3 7 1 9 5 8 2 6 10 4

出力例 3

9

入力例 4

15 100
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50

出力例 4

105

入力例 5

2 2000000000
1000000000 1000000000

出力例 5

1

Score : 366 pts

Problem Statement

In Mr. Aoki's class, N students took a test. Each student is assigned a student ID number from 1 to N, and student i scored A_i points.

Mr. Aoki is considering pairing up two different students for group work. As a measure of a pair's ability, he defines the "pair score" as the sum of the two students' scores.

Mr. Aoki wants to know how many pairs have a pair score of at least a certain threshold K.

Among all pairs of distinct students (i, j) (1 \leq i < j \leq N), find the number of pairs satisfying A_i + A_j \geq K.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 2 \times 10^9
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • All inputs are integers.

Input

N K
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of students and an integer K representing the threshold for the pair score, separated by a space.
  • The second line contains integers A_1, A_2, \ldots, A_N representing each student's score, separated by spaces.

Output

Output the number of pairs whose pair score is at least K, on a single line.


Sample Input 1

4 6
1 3 5 7

Sample Output 1

5

Sample Input 2

3 10
1 2 3

Sample Output 2

0

Sample Input 3

10 15
3 7 1 9 5 8 2 6 10 4

Sample Output 3

9

Sample Input 4

15 100
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50

Sample Output 4

105

Sample Input 5

2 2000000000
1000000000 1000000000

Sample Output 5

1