Gardening on the Train
InterviewTime limit2sMemory limit1024 MB
Given n plants with growth times a_i, plant one per day to minimize the day when the last plant ripens.
Problem
The journey of the Eastern Express is quite long, so the food brought on board is not always enough to feed its passengers. For this reason, vegetables and plants are grown on the train. But before a plant can grow, it must first be planted.
Buk has plants. The -th plant needs days to grow and ripen. Buk is very busy and cannot plant more than one plant per day, so the order of planting matters. He wants all plants to ripen as early as possible so they can be used in cooking. Help him find the minimum number of days after which all plants can ripen for some planting order.
Input
The first line contains the number of plants Buk has ().
The next line contains integers , where is the number of days the -th plant needs to grow and ripen ().
Output
Print a single line with the minimum number of days after which all plants can grow and ripen, for some planting order.