Velociraptors 301

When you go out from the toilet to go back to class you discover that a
group of velociraptors has entered to the classroms and has devoured
your classmates. The corridor where you are is closed: running away is
impossible. Velociraptors, inside the classroms digesting, will go out
at any moment to finish with you. Oh, well! It is known that this kind
of things happen sometimes.

The corridor of your high school is represented by a segment of the real
line from 0 to 2n − 2, with n doors of n classroms, placed over the
points 0, 2, 4, …, 2n − 2 of the line. The toilet where you are going
out from is placed at the point k with 0 ≤ k ≤ 2n − 2 and even k. You as
well as the velociraptors take 1 second to cover a distance unit over
the line (velociraptors are already satisfied and they are not going to
run for a miserable desert).

You are asked to, assuming that you know which velociraptors will go out
from the classroms to devour you and the moments of time t_(i) that they
will do it, and also assuming that these ones will head for you
(wherever you are) as soon as they go out, say how many seconds you can
extend your (brief but intense) life time making the right movements.

[image]

We consider that will be very useful to think in space-time diagrams as
the one on the right, where it is illustrated a possible situaton for
k = 6 and n = 11, where 3 velociraptors go out from the classroms placed
in the points 2, 4 and 14 at the moments 6, 10 and 8 respectively. The
correct answer to this case is 13.

Input

A test data contains various cases. Each case starts with three naturals
n, m and k, with 0 ≤ k ≤ 2n − 2, 1 ≤ n ≤ 10⁸ and 1 ≤ m ≤ 10000, where n
and k are as it is describe in the wording and m is the number of
velociraptors. The next m lines of the input contain a pair of numbers
c_(i), t_(i), where c_(i) is the classroom that has devoured the i-th
velociraptor and t_(i) is the moment of time that it will go out for its
desert. It is fulfilled that 0 ≤ a_(i) ≤ 2n − 2 and 0 ≤ t_(i) ≤ 10⁹ for
any i, that c_(i) and t_(i) are even, and that all the c_(i) are
different.

Output

For each case, your program must print in a line the time that you can
extend your life. As times t_(i) and classrooms are even numbers it is
fulfilled that the answer will always be an integer.

Scoring

- Test1:

  Test data with no more than 20 cases with n = m ≤ 100 and where the
  c_(i) appear sorted (as in the instance 1).

- Test2:

  Test data with no more than 20 cases with n ≤ 1000 and m ≤ 100 (as in
  the instances 2 and 3).

- Test3:

  Test data with no more than 20 cases of n ≤ 10⁸ and m ≤ 10⁴ (as in the
  instance 4).

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:16:28.387Z

© Jutge.org, 2006–2026.
https://jutge.org
