This page is still under construction.

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

Festival

Interview

Memory limit1024 MB

Summary
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.
Level

Medium7 of 10

Topics
Intervals, Heap, Greedy, Sorting
Solved
No attempts yet

Problem

You have just heard about a wonderful festival that will last for DD days, numbered from 11 to DD. There will be NN attractions at the festival. The ii-th attraction has a happiness rating of hih_i and will be available from day sis_i until day eie_i, inclusive.

You plan to choose one of the days to attend the festival. On that day, you will choose up to KK 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, TT. TT test cases follow.

The first line of each test case contains the three integers, DD, NN and KK. The next NN lines describe the attractions. The ii-th line contains hih_i, sis_i and eie_i.

Output

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the maximum total happiness you could achieve.

Limits

  • 1≤T≤1001 \le T \le 100.
  • 1≤K≤N1 \le K \le N.
  • 1≤si≤ei≤D1 \le s_i \le e_i \le D, for all ii.
  • 1≤hi≤3×1051 \le h_i \le 3 \times 10^5, for all ii.

Hint

In sample test case 1, the festival lasts D=10D=10 days, there are N=4N=4 attractions, and you can ride up to K=2K=2 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 800+1500=2300800+1500=2300. Note that you cannot also ride the third attraction, since you may only ride up to K=2K=2 attractions. This is the maximum total happiness you could achieve, so the answer is 23002300.

In sample test case 2, the festival lasts D=5D=5 days, there are N=3N=3 attractions, and you can ride up to K=3K=3 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 400+300=700400+300=700. This is the maximum total happiness you could achieve, so the answer is 700700.

Examples1

  1. Example 1

    Input
    2
    10 4 2
    800 2 8
    1500 6 9
    200 4 7
    400 3 5
    5 3 3
    400 1 3
    500 5 5
    300 2 3
    
    Expected output
    Case #1: 2300
    Case #2: 700