EIU Olympic Final Contest 2024 - A: Mystery Gift Box

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

Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Mystery Gift Box is an interesting item when shopping on online markets. The Huy store is also selling this item. The store has imported ~N~ items, with the ~i~-th item priced at ~A_i~.

Each mystery gift box selected by the store will consist of 3 items, such that the price difference between the most expensive item and the cheapest item among the selected items does not exceed ~d~.

Task: Help the store count the number of different ways to select a mystery gift box. Two selections are different if there is at least one item in one selection that is not present in the other selection.

Input:

  • The first line contains two integers ~N~ and ~d~ (~0 ≤ d ≤ 10^6~);
  • The second line contains a sequence of integers ~A_1, A_2, ..., A_N~ (~1 ≤ A_i ≤ 10^6~). The numbers are separated by spaces.

Output:

  • A single integer representing the number of possible selections.

Simple Input

5 3  
6 1 7 2 4

Simple Output

2

Notes:

There are two possible selections:

  • ~{1, 2, 4}~
  • ~{4, 6, 7}~

Constraints

  • ~60\%~ of the test cases correspond to ~1 ≤ N ≤ 200~ and ~A_i ≤ A_{i+1}~ for ~1 ≤ i < N~;
  • ~20\%~ of the test cases correspond to ~1 ≤ N ≤ 10^4~;
  • ~20\%~ of the test cases correspond to ~1 ≤ N ≤ 2 × 10^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.