Q-index
InterviewTime limit1sMemory limit512 MB
Given n citation counts, find the largest k such that at least k papers have k or more citations and the rest have at most k.
Problem
ICPC University sets its doctoral graduation requirement from the number of papers a student has published and how often those papers are cited, and it measures this with a value called the q-index. Suppose a student has published papers, where . The student's q-index is when at least papers are cited or more times and each of the remaining papers is cited at most times.
Take a student with 5 papers cited 8, 4, 5, 3, and 10 times. At least one paper is cited one or more times, but some of the other 4 papers are cited more than once, so the q-index is not 1. Fewer than 5 papers are cited 5 or more times, so it is not 5 either. Exactly 4 papers are cited 4 or more times and the one remaining paper is cited at most 4 times, so this student's q-index is 4.
Write a program that reads the citation counts of one student's papers and computes that student's q-index.
Input
The first line contains the number of papers the student published, where . The second line contains the citation counts of the papers in order, separated by spaces. Each citation count is an integer between 0 and 10000.
Output
Print the q-index on one line. The value is a non-negative integer.