Woburn Challenge 2015-16 Round 3 - Senior Division

Lex Luthor's international masquerade as a humanitarian has attracted the attention of Princess Diana of Themyscira, also known as Wonder Woman. Thanks to her unexpected addition to team Batman and Superman, all the prisoners from Cadmus have fortunately been rescued. But it's too late. Luthor has already unleashed his dangerous bio-weapon of unimaginable power – Doomsday. To destroy the reputation of Superman, Doomsday has been wreaking havoc and causing wanton destruction upon Metropolis. Doomsday was originally a deadly monster born from the depths of ancient Krypton. Having worked so hard to reanimate the abominable legend from his very own laboratories on Earth, Luthor might as well make this moment count.
The mastermind knows for a fact that while Doomsday is trampling the
city, the heroes will be intently focused on minimizing civilian
casualties. To further tie up their hands during their clash with
Doomsday, he has decided to throw in the age-old weapon of landmines.
The current street of the fight can be represented as a number line of
integer positions numbered from
Lex Luthor will control Doomsday to set off exactly one landmine of his
choice – however, this may start a chain reaction! If any other
landmines are within the initial landmine's explosion range, they'll
also go off. Their explosions may in turn set off even more landmines,
and so forth. As if fighting the deadly beast isn't enough on their
plates, Batman, Superman, and Wonder Woman will need to evacuate the
citizens of the street to safety from the landmines. To do so, they will
have to evaluate how dangerous certain positions on the street are. They
know that
For cases worth 30% of the points,
Input Specification
The first line of input will contain two space-separated integers
The next
The next
Output Specification
Output
Sample Input
4 4
10 5 12
4 5 6
15 1 1
20 10 80
101
100
0
14
Sample Output
0
3
1
4
Explanation
Position 101 is too far to be within any possible explosion.
Position 100 will be engulfed by the 4th landmine's explosion if either
the 1st, 2nd, or 4th landmine is initially set off. If the 2nd one is
set off, for example, its explosion will set off the 1st landmine, which
will set off the 4th one, which will just barely reach the point.
Position 0 will only be engulfed if the 2nd landmine is initially set
off.
No matter which landmine is initially set off, position 14 will always
be engulfed.
Comments