Albert Einstein was a renowned theoretical physicist who developed the famous equation . Albert Einstein is now working on a thesis he calls the Theory of Special Relativity which posits a set of universal truths about the behavior of light and motion of objects. When developing his thesis, Einstein selects evidence to support his hypothesis based on a "reliability ratio". He selects a set of trials from various different experiments such that the sum of the reliability ratio is maximized. He must, however, represent a variety of experiments and not select too many trials from a single one. Can you help maximize Einstein's reliability ratio sum?
Input Specification
The first line of input is representing the number of trials Einstein performed in total.
The second line of input is representing the number of trials he can select from any given experiment.
The third line of input is representing the number of trials Einstein can select to represent his data.
The next lines contain two space separated integers representing each trial's reliability ratio and which experiment it came from.
Output Specification
Print the maximum total reliability ratio that can be achieved with trials while not selecting more than trials from a single experiment.
Note: Faster input reading is encouraged for submissions in Java.
Sample Input
6
2
3
4 1
3 7
7 7
9 7
5 5
10 7
Sample Output
24
Explanation for Sample
Einstein selects the most reliable trials with scores of 10
and 9
. Because he can no longer select trials from experiment 7, he selects the trial from experiment 5 with a score of 5. The sum of these trials is 24.
Comments
This problem physically violated me in my sleep