I just found this tough question in the last year Q Paper of this exam...I dont know how to take that type of input,leave alone the logic...Can any1 help me with this program, plz... :
Question 1 Vogon zoo
On the icy planet Zorg, the Vogons are putting together a zoo. One cage will house a
collection of Kubudu dragons. Unlike the limited number of blood types found in other
creatures, Kubudu dragons have a large variety of blood types. Each dragon's blood type is fixed when it is born and is given by a positive integer.
These blood types determine how the dragons interact with each other. Two dragons
whose blood types are close to each other will quickly start fighting and eventually destroy each other. At any given time, there is a threshold K such that it is safe to put two Kubudu dragons in the same cage only if their blood types differ by K or more.
A batch of freshly hatched Kubudu dragons has arrived. Each dragon has had its blood
tested and is tagged with its blood type. The Vogon zookeeper would like to determine the size of the largest collection of dragons from this batch that can safely be placed in a single cage. Given the dragons' fighting tendencies, this means that for each pair of dragons in the cage, their blood types should differ by at least K.
For instance, suppose that K is 3 and there are 12 Kubudu dragons whose blood types
are 1, 5, 6, 1, 8, 3, 12, 2, 13, 7, 9 and 11. From this batch, the maximum number of dragons that can be placed safely in the same cage is 4.For example, the dragons with blood types
6, 12, 2 and 9.
You will be given the blood types of N Kubudu dragons and the threshold K. Your task
is to compute the size of the largest group of dragons from this collection that can safely be
placed in the same cage.
The rst line of input has two space separated integers N and K, where N is the number
of Kubudu dragons and K is the threshold below which they ght, as described above. The
second line of input consists of N space separated integers, the blood types of the N dragons.
A single integer, the size of the largest collection of dragons that can be safely placed in the
In all cases, 1 < N < 106. In 30% of the inputs, 1 < N < 5000. The blood types of the
dragons lie in the range 1 to 107.
6 0 3 -1
7 4 2 4
-3 3 -2 8
13 10 -1 -4
Note: Your program should not print anything other than what is specified in the output
format. Please remove all diagnostic print statements before making your final submission.
A program with extraneous output will be treated as incorrect!