Programming contests

ECN selejtező programozó csapatverseny, 2017. április 12.

April 12, 2017 10:00 AM – April 12, 2017 3:00 PM

Gotta Catch 'Em All!

Little Arihant has always wanted to be the best Pokemon trainer in this world. And he thinks he has achieved his goal, so he wants to quickly go and meet Professor Oak and verify this fact. But like all Pokemon trainers, he has a weird habit too. He catches Pokemons which can go through evolution to become a better one. After roaming in the Pokeworld for days, he has finally managed to catch k such Pokemons.

The way he can make a Pokemon go through evolution is NOT by making them fight battles, but by using an evolution stone. Since he has k Pokemons, he naturally needs k evolution stones for every one of them.

Now it takes little Arihant one complete day to use the evolution stone on one Pokemon. And for each Pokemon, he knows how many days they will take to evolve after the evolution stone has been used on them.

He will go to meet Professor Oak the very next day, once all his Pokemons have gone through evolution. He can select the order of applying evolution stones as he likes, so he wants to do it in such a way that he can meet Professor Oak as soon as possible!

Input Specification

The input has two lines. The first line will contain an integer k, which denotes the number of Pokemons (1 ≤ k ≤ 105). Then, a line with k integers follows, where the ith integer denotes the number of days it takes for the ith Pokemon to evolve (1 ≤ number of days ≤ 106).

Output Specification

You need to print the earliest day when little Arihant can go to meet Professor Oak.

Sample Input

  1. 2
  2. 3 1
download as text file

Output for Sample Input

  1. 5
download as text file

Sample Explanation

Here's how it happens: Day 1: He uses the evolution stone on the Pokemon which takes 3 days. Day 2: The 3-day Pokemon's first day. Arihant uses the evolution stone on the Pokemon which takes 1 day. Day 3: The 3-day Pokemon's second day. The 1-day Pokemon's first and final day. It goes through evolution. Day 4: The 3-day Pokemon's third day. It goes through evolution. All Pokemons are done, so Arihant can go to Professor Oak. Day 5: He goes to Professor Oak.

University of Debrecen; Faculty of Informatics; v. 03/01/2019