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
:.Mohib.::
2015-05-08 19:56:25
Merge sort + binary search ==> AC:) |
|
Daljeet Singh:
2015-03-24 18:27:51
O(nlogn) works |
|
cracked:
2015-03-04 21:07:44
numbers in the second line are separated by '\n' instead of ' ' |
|
kailash:
2015-02-17 13:47:57
O(n) --> TLE O(nlogn)--> AC
|
|
Rahul Jain:
2015-02-02 17:48:57
what is the range of the elements. I am using -32768 to 32767, but that gives me wrong answer |
|
MKM:
2015-01-14 17:32:34
Pretty easy! |
|
eightnoteight:
2015-01-09 08:33:01
why! why! why! why am i getting wrong answer for the same algo in python but getting accepted in C++
|
|
swordfish12:
2014-12-25 17:32:31
misleading problem name :( ... very simple problem |
|
mayank:
2014-11-25 06:29:17
Simple :) |
|
deCodeIt:
2014-10-07 07:29:51
Segmentation fault at running (2).. =="
|
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 |