Wednesday, October 10, 2007

A Good Programmer

Time Limit: 1s


A good programmer must be good with numbers. That's why we would like to test your skill in numbers. Write a program to count how many pairs could be found where the differences between numbers in a pair is P.

For example, given the list of numbers : 4 8 1 12 5

If the requested different (P), is 4, then your program should give 3 as the output, where the pairs are 4-8, 8-12, and 1-5. Same numbers could be showed up more than once on the list. In this case, the numbers should be considered as different numbers.


Input Specification
The input file consists of several test cases. First line of each test case contains two integers: N (1 <= N <= 10,000) indicating the number of items in the list, and P (1 <= P <= 10,000) indicating the requested different. The second line contains N integer(s) t1, t1, t2, ...tn (1 <= ti <= 100,000,000) which shows the list of numbers.


Output Specification
For each test case, print in a single line a number of distinct pairs where the difference between numbers in pair is P.


Sample Input
3 2
3 1 6
5 4
4 8 1 12 5
4 3
4 1 1 4


Sample Output
1
3
4


Source: BNPC-HS 2006, Final Round.

Untuk jawabannya click disini

1 comment:

Anonymous said...

Good dispatch and this mail helped me alot in my college assignement. Say thank you you for your information.