#t136. 最多做题天数
最多做题天数
Maximum Days of Problem Solving
Problem Description
Xiao Yang made a problem-solving plan to improve himself: on day , he must solve problems, otherwise he will slack off.
Xiao Yang found a problem bank consisting of 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 , the number of problem sets.
The second line contains integers , 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 problem sets with problems respectively.
- On day , he needs to solve problem; he can pick the set with problem.
- On day , he needs to solve problems; he can pick the set with problems (solving only of them).
- On day , he needs to solve problems; he can pick the set with problems (solving only of them).
By day he would need to solve problems, but the remaining set only has problem, which is insufficient, so he can keep going for at most days.
Constraints
For all test data, and are guaranteed.