Bessie the cow has enrolled in a computer science PhD program, driven by her love of computer science and also the allure of one day becoming "Dr. Bessie". Having worked for some time on her academic research, she has now published NN papers (1≤N≤1051≤N≤105), and her ii-th paper has accumulated cici citations (0≤ci≤1050≤ci≤105) from other papers in the research literature.
Bessie has heard that an academic's success can be measured by their hh-index. The hh-index is the largest number hh such that the researcher has at least hh papers each with at least hh citations. For example, a researcher with 44 papers and respective citation counts (1,100,2,3)(1,100,2,3) has an hh-index of 22, whereas if the citation counts were (1,100,3,3)(1,100,3,3) then the hh-index would be 33.
To up her hh-index, Bessie is planning to write up to KK survey articles (0≤K≤1050≤K≤105), each citing many of her past papers. However, due to page limits, she can only cite at most LL papers in each survey (0≤L≤1050≤L≤105). Of course, no paper may be cited multiple times in a single survey (but a paper may be cited in several surveys).
Help Bessie determine the maximum hh-index she may achieve after writing these survey articles. Bessie is not allowed to cite a survey from one of her surveys.
Note that Bessie's research advisor should probably inform her at some point that writing a survey solely to increase one's hh index is ethically dubious; other academics are not recommended to follow Bessie's example here.
The first line contains NN, KK, and LL.The second line contains NN space-separated integers c1,…,cNc1,…,cN.
The maximum hh-index on a single line.
4 4 1 1 100 1 1
3
In this example, Bessie may write up to 44 survey articles, each citing at most 11 paper. If she cites each of her first and third articles twice, then her hh-index becomes 33.
4 1 4 1 100 1 1
2
In this second example, Bessie may write at most a single article. If Bessie cites any of her first, third, or fourth papers at least once, her hh-index becomes 22.
Problem credits: Dhruv Rohatgi
[/hide]
(Analysis by Dhruv Rohatgi )
Sort the citation counts largest-to-smallest, and consider a bar graph where bar ii has width 11 and height cici. The hh-index of the papers before the surveys is simply the dimension of the largest square that fits under this bar graph. We want to determine how much we can increase the hh-index with KK surveys each citing LL distinct papers.
Let's binary search on the final hh-index. Then we just need a way to check whether it's possible to achieve a given hh-index hh.
It's clearly optimal to work only with the hh papers that start off with the largest citation counts. Note that we have KLKL total citations to allocate to these papers. If the total citation count of these papers is less than h2−KLh2−KL, then we cannot hope to achieve hh. This is one failure mode.
Unfortunately, it's not the only failure mode. That is, the converse of the above statement is not true, because we have an added restriction that no survey can cite a paper twice. So for example if h=3h=3, K=1K=1, and L=2L=2, and the top three papers initially have citation counts (3,3,1)(3,3,1), then we cannot raise the third paper to citation count 33 since we only have one survey. This illuminates another possible failure mode: if there is a paper with less than h−Kh−K citations initially, then we cannot achieve hh.
It turns out that these are the only two failure modes. We can prove this by induction on KK. If K=0K=0 then every paper already has at least hh citations, so we're certainly happy. Suppose K>0K>0. Every paper needs at most KK more citations. There is some set of papers which need exactly KK more citations. By the assumption on the sum of citation counts, this set has size at most LL, so with one survey we can cite all these papers (plus some others, until we've hit LL citations or this survey has cited every paper). Now we're in a situation with K−1K−1 remaining surveys, but every paper needs at most K−1K−1 more citations. Moreover, it can be checked that the total number of needed citations is now at most (K−1)L(K−1)L. So we can indeed induct, completing the proof.
Below is Danny Mittal's code, implementing the above idea.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class AcowdemiaSilver { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenizer = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tokenizer.nextToken()); int k = Integer.parseInt(tokenizer.nextToken()); int l = Integer.parseInt(tokenizer.nextToken()); Integer[] publications = new Integer[n]; tokenizer = new StringTokenizer(in.readLine()); for (int j = 0; j < n; j++) { publications[j] = Integer.parseInt(tokenizer.nextToken()); } Arrays.sort(publications, Comparator.reverseOrder()); int upper = n; int lower = 0; while (upper > lower) { int mid = (upper + lower + 1) / 2; long needed = 0; for (int j = 0; j < mid; j++) { needed += (long) Math.max(0, mid - publications[j]); } if (needed <= ((long) k) * ((long) l) && publications[mid - 1] + k >= mid) { lower = mid; } else { upper = mid - 1; } } System.out.println(upper); } }
[/hide]
翰林课程体验,退费流程快速投诉邮箱: yuxi@linstitute.net 沪ICP备2023009024号-1