#P9937. Maximizing h-index with Extra Citations
Maximizing h-index with Extra Citations
Maximizing h-index with Extra Citations
Bessie, an aspiring computer scientist, has published \(N\) research papers and her \(i\)th paper has \(c_i\) citations. The h-index is defined as the maximum integer \(h\) such that the researcher has at least \(h\) papers each having at least \(h\) citations.
Now, Bessie plans to write a survey paper to boost her h-index. Due to page limitations, she can cite at most \(L\) of her own papers, and each paper can be cited at most once in the survey paper. When a paper with \(c_i\) citations is cited in the survey, its citation count becomes \(c_i+1\).
Your task is to compute the maximum h-index Bessie can achieve after writing the survey paper. Note that citing a paper with \(c_i < h-1\) is useless in achieving an h-index of \(h\) because even after adding one citation its total would be less than \(h\).
Hint: For a candidate h-index \(h\), if there are \(A\) papers with at least \(h\) citations and \(B\) papers having exactly \(h-1\) citations, then Bessie can achieve an h-index of \(h\) if \(A + \min(B, L) \ge h\).
Note: Bessie's behavior might be frowned upon by her advisor because it involves self-citation solely to boost metrics. This problem is for algorithmic practice only.
inputFormat
The first line contains two integers (N) and (L) ((1 \le N \le 10^5) and (0 \le L \le 10^5)). The second line contains (N) integers (c_1, c_2, \dots, c_N) (each (0 \le c_i \le 10^5)) representing the citation counts of Bessie's papers.
outputFormat
Output a single integer: the maximum h-index Bessie can achieve after writing her survey paper.
sample
4 1
1 100 2 3
3