This page is still under construction.

Parts of this page are still being built. What you see may change.

Quiz

Interview

Time limit1sMemory limit1024 MB

Summary
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 NN questions in total, divided among MM 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 BB 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 KK questions. What is the maximum number of points she can score?

Input

The first line contains four integers 1≤N≤10001 \le N \le 1000, 1≤M≤N1 \le M \le N, 1≤K≤N1 \le K \le N, 1≤B≤100 0001 \le B \le 100\,000. The following NN lines each contain two integers: the points awarded for answering the question (an integer between 1 and 1 0001\,000) and the category it belongs to (between 1 and MM). 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 (300+400=700300 + 400 = 700 points) and the only question in category 2 (200200 points). Since these were all the questions in those two categories, she gets two bonuses, for a total of 200+700+2⋅1000=2900200 + 700 + 2 \cdot 1000 = 2900 points.

Examples2

  1. Example 1

    Input
    5 3 3 1000
    300 1
    400 1
    200 2
    200 3
    300 3
    
    Expected output
    2900
    
  2. Example 2

    Input
    5 3 3 1
    300 1
    400 1
    200 2
    300 3
    200 3
    
    Expected output
    1001