Problem Statement | |||||||||||||
The heat death of the universe occurs when all available energy has moved from "hot" (high energy) locations to "cold" (low energy) locations. Hot and cold are relative concepts--energy can flow from one location to another if and only if the energy level of the first location is at least 2 units greater than the energy level of the second location. Heat death occurs when there are no more locations between which energy can flow. Naturally, we would like to put off heat death for as long as possible. You will be given a int[] energy that contains the energy levels of all locations in a closed system at time 0. Every microsecond, a random pair of locations whose energy levels differ by at least two units will be chosen, and a single unit of energy will flow from the hotter location to the colder location. Notice that the locations do not have to be adjacent. Depending on the order in which pairs of locations are chosen, heat death could arrive in different amounts of time. Calculate and return the maximum number of microseconds until the system reaches heat death. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | energy contains between 2 and 50 elements, inclusive. | ||||||||||||
- | Each element of energy is between 1 and 999, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|