#P7785. H-Index Calculation

    ID: 20971 Type: Default 1000ms 256MiB

H-Index Calculation

H-Index Calculation

Given a sequence of integers, find the maximum integer \(H\) such that there are at least \(H\) numbers in the sequence which are greater than or equal to \(H\). This problem is similar to the computation of the H-index in academic contexts.

inputFormat

The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)), representing the number of elements in the sequence.
The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) (each \(0 \le a_i \le 10^9\)), separated by spaces.

outputFormat

Output a single integer \(H\) which is the maximum number satisfying the condition that there are at least \(H\) numbers in the sequence that are \(\geq H\).

sample

5
3 0 6 1 5
3