#P9937. [USACO21OPEN] Acowdemia I B

[USACO21OPEN] Acowdemia I B

Problem Description

Because of her love for computer science, and the temptation of one day becoming “Dr. Bessie”, the cow Bessie has started pursuing a PhD in computer science. After some time doing research, she has published NN papers (1N1051 \le N \le 10^5), and her ii-th paper has received cic_i citations from other research papers (0ci1050 \le c_i \le 10^5).

Bessie has heard that academic achievement can be measured using the hh-index. The hh-index is the largest integer hh such that the researcher has at least hh papers with at least hh citations each. For example, if a researcher has 44 papers with citation counts (1,100,2,3)(1,100,2,3), then the hh-index is 22. However, if the citation counts are (1,100,3,3)(1,100,3,3), then the hh-index would be 33.

To increase her hh-index, Bessie plans to write a survey paper and cite some of her own papers in it. Because of page limits, she can cite at most LL papers in this survey (0L1050 \le L \le 10^5), and she can cite each of her papers at most once.

Please help Bessie find the maximum hh-index she can achieve after writing this survey.

Note that Bessie’s advisor may tell her that writing a survey purely to increase her hh-index might be considered academic misconduct; we do not recommend other researchers imitate Bessie’s behavior.

Input Format

The first line contains NN and LL.

The second line contains NN space-separated integers c1,,cNc_1,\ldots,c_N.

Output Format

Output the maximum hh-index Bessie can achieve after writing the survey.

4 0
1 100 2 3
2
4 1
1 100 2 3
3

Hint

Sample Explanation 1

Bessie cannot cite any of her previously written papers. As mentioned above, the hh-index of (1,100,2,3)(1,100,2,3) is 22.

Sample Explanation 2

If Bessie cites her third paper, the citation counts become (1,100,3,3)(1,100,3,3). As mentioned above, the hh-index for these citation counts is 33.

Test Point Properties

  • Test points 171-7 satisfy N100N \le 100.
  • Test points 8108-10 satisfy N1000N \le 1000.
  • Test points 111711-17 satisfy N105N \le 10^5.

Translated by ChatGPT 5