#K75012. Counting Valid Teams
Counting Valid Teams
Counting Valid Teams
In this problem, you are given several test cases. In each test case, there are n students with individual skill levels. You are also given four integers: n, l, r, and d. Although l and r represent the minimum and maximum skill levels (and can be regarded as constraints), the main goal is to count the number of valid teams that can be formed from these students. A team is formed by choosing any 3 students. A team is considered valid if there exists at least one pair of students within the team such that the absolute difference of their skill levels satisfies the inequality
[ |s_i - s_j| \le d ]
where (s_i) and (s_j) are the skill levels of two distinct students in the team. The input is read from standard input and the corresponding output should be printed to standard output. Each test case's answer should be printed on a new line.
inputFormat
The first line of input contains a single integer T representing the number of test cases. Each test case consists of two lines:
-
The first line contains four space-separated integers: n, l, r, d, where n is the number of students and l, r are the minimum and maximum skill levels respectively (they are provided for informational purposes), and d is the allowed absolute difference constraint.
-
The second line contains n space-separated integers representing the skill levels of the students.
outputFormat
For each test case, print a single integer in a new line indicating the number of valid teams (i.e., teams of 3 students for which there exists at least one pair whose absolute difference of skill levels is less than or equal to d).## sample
2
4 1 4 1
1 2 3 4
5 1 5 2
1 3 2 5 4
4
10
</p>