Problem 372
H-Index
Medium · 20 pts · Array, Sorting, Counting
Problem
A researcher's h-index is the largest number h such that they have at least h papers that were each cited at least h times. Given the citation count of each paper, compute the h-index. For example, with citations 3 0 6 1 5 the researcher has 3 papers with at least 3 citations (3, 6 and 5), but not 4 papers with at least 4 citations, so the h-index is 3.
Input
First line: N, the number of papers. Second line: the N citation counts.
Output
Print the h-index.
Constraints
1 <= N <= 100000; 0 <= citations <= 1000
Example input
5 3 0 6 1 5
Example output
3
Explanation
With citations 3 0 6 1 5, three papers have at least 3 citations (3, 6 and 5), but only two papers have at least 4, so the h-index is 3.