#P7785. [COCI 2016/2017 #6] Hindeks

[COCI 2016/2017 #6] Hindeks

Description

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

Input Format

The first line contains a positive integer NN, which denotes the number of elements in the sequence.

The second line contains NN integers AiA_i, which denote the elements of the sequence.

Output Format

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

5
1 1 4 8 1 
2
5
8 5 3 4 10
4

Hint

Sample Explanation #1.

There are 22 numbers greater than or equal to 22, namely 44 and 88.

Sample Explanation #2.

There are 44 numbers greater than or equal to 44, namely 88, 55, 44, and 1010.

Constraints.

For 100%100\% of the testdata, 1N5×1051\le N\le 5\times 10^5, 0Ai1×1060\le A_i\le 1\times 10^6.

Notes.

The score of this problem follows the original COCI settings, with a full score of 5050.

Translated from COCI2016_2017 CONTEST #6 T1 HINDEKS.

Translated by ChatGPT 5