HACKRNDM - Hacking the random number generator
You recently wrote a random number generator code for a web application and now you notice that some cracker has cracked it. It now gives numbers at a difference of some given value k more predominantly. You being a hacker decide to write a code that will take in n numbers as input and a value k and find the total number of pairs of numbers whose absolute difference is equal to k, in order to assist you in your random number generator testing.
NOTE: All values fit in the range of a signed integer, n, k>=1
Input
1st line contains n & k.
2nd line contains n numbers of the set. All the n numbers are assured to be distinct.
(Edited: n <= 10^5)
Output
One integer saying the no of pairs of numbers that have a diff k.
Example
Input: 5 2
1 5 3 4 2 Output: 3
hide comments
Mathan Kumar:
2012-05-03 23:13:18
o(n) is enough using map in c++.. |
|
PANKAJ SAINI:
2012-04-22 03:06:45
what is the limit of n?? |
|
arjun:
2012-03-14 14:38:48
O(nlogn) +O(n) |
|
张翼德:
2012-02-06 21:10:13
read question twice and google wat predominantly means haha:) |
|
PubLic_AvenGeR:
2012-01-15 15:34:27
nlogn passes with ease....Good ques anyways..... :) |
|
BOND:
2012-01-05 12:46:11
just think how to use increasing sequence ... |
|
Aradhya:
2011-12-31 15:40:47
plz tell the range of n... |
|
Allada Revanth Kumar:
2011-12-31 12:37:01
seems very easy problem... but could not understand why i am getting TLE.. please help |
|
bristy:
2011-12-28 18:31:30
@admin_
|
|
Anurag Aggarwal:
2011-12-23 06:45:26
@author
|
Added by: | vijay |
Date: | 2011-10-15 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Own Problem |