Theory of Relativity

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Java 8 4.0s
Memory limit: 128M

Author:
Problem type

Albert Einstein was a renowned theoretical physicist who developed the famous equation E=mc^2. 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 n (1 \le n \le 10^6) representing the number of trials Einstein performed in total.
The second line of input is m (1 \le m \le n) representing the number of trials he can select from any given experiment.
The third line of input is q (1 \le q \le n) representing the number of trials Einstein can select to represent his data.
The next n lines contain two space separated integers n_1, n_2 (1 \le n_i \le 10^6) 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 q trials while not selecting more than m 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


  • 0
    Serog1sPerog1s  commented on April 11, 2020, 10:46 p.m.

    This problem physically violated me in my sleep