Quiz | 프로그래밍의 벗 PivotOJ
PivotOJ

Quiz

시간 제한: 1000ms메모리 제한: 1024MB출처: Programmeringsolympiaden 2016 — finalBOJ 21327

문제

In the quiz ProgrammeringsQuiz there are NN questions in total, distributed over MM different categories (for example, algorithm theory, compiler construction or Sven knowledge).

The questions are worth different amounts of points. Additionally, you will get a bonus BB if you answer all questions in a certain category. Simone has participated in Programmeringsolympiaden since 8th grade, so she is able to answer all the questions.

Unfortunately, there is a time limit to the quiz. Despite never giving the wrong answer, Simone will only have time to answer KK questions. What is the maximum number of points she can achieve?

입력

The first line consists of four integers 1N10001 \le N \le 1000, 1MN1 \le M \le N, 1KN1 \le K \le N, 1B1000001 \le B \le 100\,000. The following NN lines consist of two integers each: the points given for answering the question (an integer between 11 and 10001\,000) and which category it belongs to (between 11 and MM). Each category will have at least one question.

출력

Print one line containing the maximal possible number of points.

힌트

In the first sample Simone answers both questions from category 1 (300+400=700300 + 400 = 700 points) and the only question in category 2 (200200 points). Since these were the only questions in these two categories we get two bonuses, which gives a total of 200+700+21000=2900200 + 700 + 2 \cdot 1000 = 2900 points.

예제

예제 1

입력
5 3 3 1000
300 1
400 1
200 2
200 3
300 3
출력
2900

예제 2

입력
5 3 3 1
300 1
400 1
200 2
300 3
200 3
출력
1001
코드를 제출하려면 로그인하세요.