#P16748. [GKS 2020 #A] Plates

[GKS 2020 #A] Plates

Problem Description

Dr. Patel has NN stacks of plates. Each stack contains KK plates. Each plate has a positive beauty value, describing how beautiful it looks.

Dr. Patel would like to take exactly PP plates to use for dinner tonight. If he would like to take a plate in a stack, he must also take all of the plates above it in that stack as well.

Help Dr. Patel pick the PP plates that would maximize the total sum of beauty values.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing the three integers NN, KK and PP. Then, NN lines follow. The ii-th line contains KK integers, describing the beauty values of each stack of plates from top to bottom.

Output Format

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 sum of beauty values that Dr. Patel could pick.

2
2 4 5
10 10 100 30
80 50 10 50
3 2 3
80 80
15 50
20 10
Case #1: 250
Case #2: 180

Hint

In Sample Case #1, Dr. Patel needs to pick P=5P=5 plates:

  • He can pick the top 33 plates from the first stack (10+10+100=12010+10+100 = 120).
  • He can pick the top 22 plates from the second stack (80+50=13080+50=130) .

In total, the sum of beauty values is 250250.

In Sample Case #2, Dr. Patel needs to pick P=3P=3 plates:

  • He can pick the top 22 plates from the first stack (80+80=16080+80=160).
  • He can pick no plates from the second stack.
  • He can pick the top plate from the third stack (2020).

In total, the sum of beauty values is 180180.

Limits

1T1001 \le T \le 100.

1K301 \le K \le 30.

1PN×K1 \le P \le N \times K.

The beauty values are between 11 and 100100, inclusive.

Test Set 1

1N31 \le N \le 3.

Test Set 2

1N501 \le N \le 50.