Festival
InterviewMemory limit1024 MB
Each attraction is open on a day interval and has a happiness value; pick one day and at most K open attractions to maximize the sum.
Problem
You have just heard about a wonderful festival that will last for days, numbered from to . There will be attractions at the festival. The -th attraction has a happiness rating of and will be available from day until day , inclusive.
You plan to choose one of the days to attend the festival. On that day, you will choose up to attractions to ride. Your total happiness will be the sum of happiness ratings of the attractions you chose to ride.
What is the maximum total happiness you could achieve?
Input
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains the three integers, , and . The next lines describe the attractions. The -th line contains , and .
Output
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1) and is the maximum total happiness you could achieve.
Limits
- .
- .
- , for all .
- , for all .
Hint
In sample test case 1, the festival lasts days, there are attractions, and you can ride up to attractions.
If you choose to attend the festival on the 6th day, you could ride the first and second attractions for a total happiness of . Note that you cannot also ride the third attraction, since you may only ride up to attractions. This is the maximum total happiness you could achieve, so the answer is .
In sample test case 2, the festival lasts days, there are attractions, and you can ride up to attractions.
If you choose to attend the festival on the 3rd day, you could ride the first and third attractions for a total happiness of . This is the maximum total happiness you could achieve, so the answer is .