Woburn Challenge 2016-17 Round 4 - Senior Division

"Ugh. Timber wolves. Look at these dum-dums. Bet ya a nickel one of
them's gonna howl."
"And there it is. I mean, what is it with wolves and the howling?"
Judy and Nick's search for a group of kidnapped animals has led them to
the abandoned Cliffside Asylum. The building is being guarded by a pack
of
wolves, who will all need to somehow be
distracted if Judy and Nick are to sneak by and investigate the
premises.
The wolves are all standing in a row, which can be represented as a
number line. The wolf is at position
on the line, and has an alpha rank of
,
with the pack's most respected members having the smallest
ranks. All of the wolves are standing at distinct positions, and have
distinct ranks.
Wolves sometimes like to howl out of the blue, and they sometimes like
to howl when they hear other wolves howling. If wolf decides to
start a howl, then each wolf with a larger alpha rank standing within
some howling radius
of wolf
will be obligated to join in (in
other words, each wolf
such that
,
, and
). Each wolf
which joins the howl in this
fashion may in turn cause even more wolves to start howling themselves
(wolves
which have larger alpha ranks than wolf
and are standing
close enough to him), and so on.
Judy and Nick figure that they can trick any
wolves
of their choice into starting to howl. They're hoping that this plan can
result in all
wolves joining the howl, allowing them to sneak by.
Unfortunately, they don't know how large the howling radius
is, only
that it's some positive integer, so they can't predict how things will
go! Still, they'd like to get an idea of how likely their plan is to
work, by determining the minimum howling radius
which would be
necessary to allow them to get all
wolves to join a howl initially
started by some
of the wolves.
In test cases worth of the points,
.
Input Specification
The first line of input consists of two space-separated integers and
.
lines follow, the
of which consists of two space-separated
integers
and
(for
).
Output Specification
Output a single integer - the minimum howling radius necessary such
that all
wolves can be made to join a howl started by
of them.
Sample Input
7 2
6 8
10 12
12 10
8 1
3 5
13 7
5 4
Sample Output
3
Sample Explanation
If and wolves
and
start a howl, all
wolves will end up
joining it.
On the other hand, if , then no
initial wolves can be chosen
such that all
wolves will end up howling.
Comments