#P16858. [GKS 2021 #F] Festival

[GKS 2021 #F] Festival

Problem Description

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 Format

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 Format

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

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
Case #1: 2300
Case #2: 700

Hint

In sample test case 11, 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 66th 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 22, 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 33rd 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.

Limits

1T1001 \le T \le 100.

1KN1 \le K \le N.

1sieiD1 \le s_i \le e_i \le D, for all ii.

1hi3×1051 \le h_i \le 3 \times 10^5, for all ii.

Test Set 11

1N10001 \le N \le 1000.

1D10001 \le D \le 1000.

Test Set 22

For at most 1010 test cases:

  • 1N3×1051 \le N \le 3 \times 10^5.
  • 1D3×1051 \le D \le 3 \times 10^5.

For the remaining cases, 1N,D10001 \le N, D \le 1000.