Quiz
InterviewTime limit1sMemory limit1024 MB
Pick at most K questions out of N, where finishing every question in a category adds a bonus B, and maximize the total score.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Dynamic programming, Array
- Solved
- No attempts yet
Problem
The quiz ProgrammeringsQuiz has questions in total, divided among different categories (for example algorithm theory, compiler construction, or Sven knowledge).
The questions are worth different numbers of points. In addition, you get a bonus of points if you answer every question in a category. Simone has taken part in Programmeringsolympiaden since 8th grade, so she can answer all the questions.
Unfortunately, the quiz has a time limit. Simone never gives a wrong answer, but she only has time to answer questions. What is the maximum number of points she can score?
Input
The first line contains four integers , , , . The following lines each contain two integers: the points awarded for answering the question (an integer between 1 and ) and the category it belongs to (between 1 and ). Every category has at least one question.
Output
Print the maximum possible number of points on one line.
Hint
In the first sample Simone answers both questions in category 1 ( points) and the only question in category 2 ( points). Since these were all the questions in those two categories, she gets two bonuses, for a total of points.