P7785 [COCI 2016/2017 #6] Hindeks

Description

Given a sequence, please find the largest integer $H$ such that in the original sequence there are at least $H$ numbers $\ge H$.

Input Format

The first line contains a positive integer $N$, which denotes the number of elements in the sequence. The second line contains $N$ integers $A_i$, which denote the elements of the sequence.

Output Format

Output one line containing an integer $H$, which is the largest integer that satisfies the condition.

Explanation/Hint

**Sample Explanation #1.** There are $2$ numbers greater than or equal to $2$, namely $4$ and $8$. **Sample Explanation #2.** There are $4$ numbers greater than or equal to $4$, namely $8$, $5$, $4$, and $10$. **Constraints.** For $100\%$ of the testdata, $1\le N\le 5\times 10^5$, $0\le A_i\le 1\times 10^6$. **Notes.** The score of this problem follows the original COCI settings, with a full score of $50$. Translated from [COCI2016_2017](https://hsin.hr/coci/archive/2016_2017/) [CONTEST #6](https://hsin.hr/coci/archive/2016_2017/contest6_tasks.pdf) _**T1 HINDEKS**_. Translated by ChatGPT 5