#P4953. Cow Bicycle Race
Cow Bicycle Race
Cow Bicycle Race
The cow bicycle team is composed of N cows that are about to participate in a race consisting of D laps. The cows line up in a straight line, and because of air resistance, when the team rides at a speed of x laps per minute the following energy consumption occurs during that minute:
- The lead cow uses x2 units of energy.
- Every other cow uses x units of energy.
Initially every cow has the same energy value E. During the race if a cow runs out of energy it drops out and can no longer continue. In order for the team to finish the race, at least one cow must reach the finish line.
The race is conducted in minutes. At the beginning of each minute, the team must designate one cow to be the leader. The designated leader must not drop out during that minute, which means that the cow chosen as leader must have enough energy to pay the higher cost (x2) for that minute. Also, note that the number of laps covered in each minute (x) must be a positive integer.
Assuming you can plan the strategy (i.e. choose the speed for each minute and decide which cow leads in each minute) over a total of m minutes with speeds x1, x2, ..., xm (all positive integers) so that:
- The total laps covered, S = x1 + x2 + ... + xm, is at least D.
- There exists at least one cow (the "champion") that finishes with non‐negative energy. Note that every cow always rides every minute and therefore loses xi energy in the ith minute. In addition, if a cow serves as leader in some minute, it incurs an extra cost of x2 - x for that minute.
Furthermore, since there are N cows available, at most N - 1 minutes can be led by cows other than the champion. In the remaining minutes, the champion must lead, incurring the extra cost. If we denote by L the number of minutes the champion leads, then we must have L ≥ m - (N - 1).
Thus, if the champion never leads the race, its energy consumption is simply S. If it leads in L minutes, its total energy consumption is:
\( S + \sum_{i \in \text{champion leader minutes}} (x_i^2 - x_i) \)
The challenge is to determine the minimum number of minutes m required to complete at least D laps, by choosing an integer speed x for each minute (it is optimal to choose the same speed throughout) and an assignment of leader minutes such that the champion cow (which must finish with energy at least 0) satisfies:
\( m \cdot x + L \cdot (x^2 - x) \le E \)
with \( L = \max(0, m - N + 1) \) and also m · x \ge D.
If it is not possible to finish the race under the given energy constraints, output -1
.
Your task is to compute the minimum minutes required to complete the race.
inputFormat
The input consists of a single line with three space‐separated integers:
N
– the number of cows in the team.D
– the total number of laps in the race.E
– the initial energy of each cow.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ D, E ≤ 109
outputFormat
Output a single integer, which is the minimum number of minutes needed to finish the race under the given conditions. If it is impossible for any cow to complete the race, output -1
.
sample
3 10 10
10