eolymp
bolt
Try our new interface for solving problems
Problems

Planting Trees

Planting Trees

\includegraphics{https://static.e-olymp.com/content/e4/e446a462f954230f859e00e0cc551a8b0b637d94.jpg} Farmer Jon has recently bought $n$ tree seedlings that he wants to plant in his yard. It takes $1$ day to plant a seedling, and for each tree, Jon knows exactly how many days after planting it will take to reach full maturity. Jon would also like to throw a party for his farmer friends, but in order to impress them, he would like to organize the party only after all the trees have grown. More precisely, the party can be organized at the earliest the next day after the last tree has grown up. Help Jon find out the earliest day the party can take place. Jon can choose the order of planting the trees as he likes, so he wants to plant the trees in such a way that the party will be as soon as possible. \InputFile The first line contains a single integer $n~(1 \le n \le 10^5)$ denoting the number of seedlings. Then a line with $n$ integers $t_i~(1 \le t_i \le 10^6)$ follows, where $t_i$ denotes the number of days it takes for the $i$-th tree to grow. \OutputFile Print one integer, denoting the earliest day when the party can be organized. The days are numbered $1, 2, 3, ...$ starting from the current moment.
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
2 3 4 3
Output example #1
7
Input example #2
6
39 38 9 35 39 20
Output example #2
42
Source 2013 ACM Nordic (NCPC), October 5, Problem A