Eastern Express Cars
InterviewTime limit2sMemory limit1024 MB
Given passenger counts in n cars, find the minimum time to unload everyone when one step empties a car or removes one passenger from each nonempty car.
Statement
A train runs from Istanbul to London with cars. Car holds passengers, and all of them want to get off at the final stop, Victoria Station in London. The train has many cars and many passengers, so the crew needs a plan for unloading them.
In one unit of time, the conductor can do one of two things. The conductor can empty an entire car, or let one passenger out of every car that still has passengers.
The passengers are in a hurry and the conductor is in a panic. Find the minimum time needed to unload all passengers from the train.
Input
The first line contains one integer , the number of cars .
The second line contains integers , where is the number of passengers in the -th car.
Output
Print one integer, the minimum time needed to unload all passengers.