#t136. 最多做题天数

最多做题天数

Maximum Days of Problem Solving

Problem Description

Xiao Yang made a problem-solving plan to improve himself: on day kk, he must solve kk problems, otherwise he will slack off.

Xiao Yang found a problem bank consisting of nn problem sets, each containing some number of problems. He is very picky: he will use each problem set at most once, and on any given day he can only use problems from a single problem set, after which that set is discarded and cannot be used again. For each problem set, he does not have to finish all the problems in it.

The question is: what is the maximum number of consecutive days Xiao Yang can keep up his plan before he has to slack off?

Input Format

The first line contains an integer nn, the number of problem sets.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n, the number of problems in each problem set.

Output Format

Output one line containing a single integer: the answer.

Sample Input

4
3 1 4 1

Sample Output

3

Sample Explanation

There are 44 problem sets with 3,1,4,13, 1, 4, 1 problems respectively.

  • On day 11, he needs to solve 11 problem; he can pick the set with 11 problem.
  • On day 22, he needs to solve 22 problems; he can pick the set with 33 problems (solving only 22 of them).
  • On day 33, he needs to solve 33 problems; he can pick the set with 44 problems (solving only 33 of them).

By day 44 he would need to solve 44 problems, but the remaining set only has 11 problem, which is insufficient, so he can keep going for at most 33 days.

Constraints

For all test data, 1≤n≤1061 \le n \le 10^6 and 1≤ai≤1091 \le a_i \le 10^9 are guaranteed.