#P3550. Byteasar's Taxi Journey

    ID: 16804 Type: Default 1000ms 256MiB

Byteasar's Taxi Journey

Byteasar's Taxi Journey

Byteasar wants to take a taxi from the town Bytehole (position 0) to the town Bytepit (position \(m\)) along a straight line. Exactly \(d\) kilometres from Bytehole there is a taxi depot with \(n\) taxis (numbered from 1 to \(n\)). Each taxi \(i\) has enough fuel to go at most \(x_i\) kilometres.

All taxis start at the depot (position \(d\)) but need not return there. Byteasar can change taxis at any point along the journey. When a taxi is used, it must first drive from the depot to Byteasar's current position and then carry him forward. Note that the total distance traveled by the taxi is the sum of:

  • the distance from the depot to the pickup point, and
  • the distance from the pickup point to the drop‐off point.

More formally, let \(c\) denote Byteasar's current position. When using a taxi with fuel \(x\):

  • If \(c \le d\), the taxi must travel \((d - c)\) to reach Byteasar, and then can drive him forward by at most \(x - (d-c)\) kilometres. Hence the maximum drop‐off point is at \[ B \le c + \Bigl(x - (d-c)\Bigr) = x - d + 2c. \]
  • If \(c \ge d\), the taxi is behind Byteasar less than or equal to \(c-d\) kilometres. In that case, the maximum drop‐off point is \[ B \le x + d, \] since the taxi uses \((c-d)\) to reach Byteasar and can then drive him forward by at most \(x - (c-d)\) kilometres.

Your task is to determine whether Byteasar can be driven from Bytehole (position 0) to Bytepit (position \(m\)). If so, output the minimum number of taxis required; otherwise, output -1.

inputFormat

The input consists of two lines:

  1. The first line contains three integers \(m\), \(d\) and \(n\) (in that order), where \(m\) (\(m > d \ge 0\)) is the total distance from Bytehole to Bytepit, \(d\) (\(\ge 0\)) is the distance from Bytehole to the taxi depot, and \(n\) (\(n \ge 1\)) is the number of taxis.
  2. The second line contains \(n\) integers \(x_1, x_2, \dots, x_n\), where each \(x_i\) (\(x_i \ge 0\)) is the maximum distance taxi \(i\) can travel.

It is guaranteed that all values are integers.

outputFormat

Output a single integer — the minimum number of taxis needed to transport Byteasar from position 0 to position \(m\). If it is impossible, output -1.

sample

10 5 3
15 10 7
1