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
tech{{i}}:
2011-12-21 07:19:10
the same code when submitted in java gives TLE but accepted in c++....why this????
|
|
.::Manish Kumar::.:
2011-11-27 17:48:26
Misleading problem-name. I thought something would be there regarding Random Number gen. |
|
^::^:
2011-11-18 11:31:33
Will a number repeat??? |
|
^::^:
2011-11-18 11:31:00
will a number repeat???? |
|
****** *** *****:
2011-10-29 03:14:18
2^32 is the limit ?? Last edit: 2011-10-29 04:30:46 |
|
Mohamed Maher:
2011-10-29 00:33:53
what are the limits?? |
|
Chandan Giri:
2011-10-21 10:21:06
easy problem.. :) |
|
sri:
2011-10-19 14:40:12
what is the limit for n? |
|
Nnavneetsinha:
2011-10-19 05:06:57
@vijay be more formal in problem description writing |
|
sharad:
2011-10-19 05:06:57
O(n)+O(nlogn) is ok need not to do binary search every time..:)
|
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 |