#P7894. Checker Leap Simulation

    ID: 21079 Type: Default 1000ms 256MiB

Checker Leap Simulation

Checker Leap Simulation

In this problem, an infinite number line contains n immovable checkers at fixed positions \( x_1,x_2,\dots,x_n \). A movable checker is placed at a given starting position, and it can jump leftward according to the following rule:

  • If the movable checker is at position \( a \) and jumps to position \( b \) (with \( b < a \)), there must be exactly one immovable checker in the closed interval \( [b,a] \). Let that checker be at position \( m \).
  • Formally, the condition is \[ \sum_{i=1}^{n} \mathbb{1}_{[b,a]}(x_i)=1 \] and it is required that \[ m=\frac{a+b}{2}. \]

If a valid jump exists, the movable checker moves from \( a \) to \( b = 2m-a \), and the process repeats. Each query is independent. For each starting position given in the queries, determine the maximum number of jumps the movable checker can perform.

Note: All immovable checkers remain fixed throughout all queries.

inputFormat

The input begins with a line containing two integers \( n \) and \( q \):

n q

The second line contains \( n \) space-separated integers \( x_1,x_2,\dots,x_n \) representing the positions of the immovable checkers.

Each of the following \( q \) lines contains a single integer representing the starting position of the movable checker for that query.

outputFormat

For each query, output a single integer on a new line, which is the maximum number of jumps the movable checker can perform following the rules.

sample

2 3
2 5
7
10
6
2

0 2

</p>