#C10332. Minimum Minutes to Evacuate People

    ID: 39526 Type: Default 1000ms 256MiB

Minimum Minutes to Evacuate People

Minimum Minutes to Evacuate People

You are given a scenario where a group of people must be evacuated from one side of a series of bridges to the other side. The bridges have varying capacities indicating the maximum number of people that can cross in one minute. You are provided with the following parameters:

  • N: the number of bridges.
  • A: the number of people waiting on the starting side.
  • B: the number of people already on the destination side (this parameter is provided but does not affect the evacuation time calculation).
  • capacities: an array of integers where each element represents the capacity of a bridge per minute.

Your task is to determine the minimum number of minutes required to evacuate all the people from the starting side across all the bridges. In one minute, each bridge can evacuate up to its capacity in people. If it is impossible to evacuate all people because all bridges have zero capacity while there are still people waiting, output -1.

The answer should be computed using the ceiling division of the number of people by the total capacity per minute.

The formula used for the calculation is:

\[ \text{minutes} = \left\lceil \frac{A}{\sum_{i=1}^{N} c_i} \right\rceil, \]

where \(c_i\) is the capacity of the i-th bridge.

inputFormat

The input is read from standard input (stdin) with the following format:

N A B
c1 c2 ... cN

Where:

  • N is the number of bridges.
  • A is the number of people on the starting side.
  • B is the number of people on the destination side initially.
  • The next line contains N integers representing the capacities of each bridge.

outputFormat

Output a single integer to standard output (stdout) which is the minimum number of minutes required to evacuate all people. If it is impossible to evacuate all the people due to zero total capacity when A > 0, output -1.

## sample
3 100 0
50 60 40
1